当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql部分替换sql语句分享

mysql部分替换sql语句分享

2017年12月12日  | 移动技术网IT编程  | 我要评论

邓文迪交往21岁小鲜肉,模拟试卷,老北京布鞋图片

将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`) < 8

将所有'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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网