欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql部分替换sql语句分享

程序员文章站 2023-12-18 14:25:52
将cdb_pms表subject字段中的welcom to替换成 欢迎光临 复制代码 代码如下: update `cdb_pms` set `subject` = repl...

将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

上一篇:

下一篇: