>데이터 베이스 >MySQL 튜토리얼 >mysql部分替换sql语句分享_MySQL

mysql部分替换sql语句分享_MySQL

WBOY
WBOY원래의
2016-06-01 13:22:31842검색

bitsCN.com

将cdb_pms表subject字段中的Welcom to替换成 欢迎光临

UPDATE `cdb_pms`
SET `subject` = REPLACE(`subject`, 'Welcome to', '欢迎光临')
WHERE INSTR(`subject`,'Welcome to') > 0

替换cdb_posts表的message字段,将“viewthread.php?tid=3989”替换成“viewthread.php?tid=16546”

UPDATE `cdb_posts`
SET `message`= REPLACE(`message`, 'viewthread.php?tid=3989', 'viewthread.php?tid=16546')
WHERE INSTR(`message`,'viewthread.php?tid=3989') > 0 ;

删除所有的空格

UPDATE `es_product` SET `pro_pub_time` = TRIM(`pro_pub_time`)

删除所有饱含'['或者']'或者'.'的字符

UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, '[','') WHERE INSTR(`pro_pub_time`,'[') > 0
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, ']','') WHERE INSTR(`pro_pub_time`,']') > 0
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, '.','-') WHERE INSTR(`pro_pub_time`,'.') > 0

替换所有含中文'-'的为英文'-'

UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, '-','-') WHERE INSTR(`pro_pub_time`,'-') > 0

将所有的年月都替换成'-'

UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, '年','-') WHERE INSTR(`pro_pub_time`,'年') > 0
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, '月','-') WHERE INSTR(`pro_pub_time`,'月') > 0

将所有'2005-04-'这种类型的替换成'2005-04-01'

UPDATE `es_product` SET `pro_pub_time` = CONCAT( `pro_pub_time`, '01') WHERE SUBSTRING_INDEX( `pro_pub_time`, '-', -1) = '' AND LENGTH(`pro_pub_time`) > 0 AND LENGTH(`pro_pub_time`) > 5

将所有'2005-'这种类型替换成'2005-01-01'

UPDATE `es_product` SET `pro_pub_time` = CONCAT( `pro_pub_time`, '01-01') WHERE INSTR(`pro_pub_time`,'-') > 0 AND LENGTH(`pro_pub_time`) = 5

将所有 饱含'-',但是位数小于8的改成追加'-01'

UPDATE `es_product` SET `pro_pub_time` = CONCAT( `pro_pub_time`, '-01') WHERE INSTR(`pro_pub_time`,'-') > 0 AND LENGTH(`pro_pub_time`)
将所有'2005'这样的改成'2005-01-01'

UPDATE `es_product` SET `pro_pub_time` = CONCAT(`pro_pub_time`,'-01-01') WHERE INSTR(`pro_pub_time`,'-') = 0 AND LENGTH(`pro_pub_time`) = 4

最后将所有'2005-01-01'格式化成'2005年01月'

UPDATE `es_product` SET `pro_pub_time` = DATE_FORMAT(`pro_pub_time`,'%Y年%m月') WHERE INSTR(`pro_pub_time`,'-') > 0

bitsCN.com
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.