您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql 中replace()批量替换指定字符语句

2024/4/10 12:38:21发布14次查看
本文章介绍了关于一个mysql 中replace()批量替换指定字符语句的,我们利用了update set和replace一起工作,这样就可以实现我们想要的东西了。
将cdb_pms表subject字段中的welcom to替换成 欢迎光临
 代码如下 复制代码
update `cdb_pms`
set `subject` = replace(`subject`, 'welcome to', '欢迎光临')
where instr(`subject`,'welcome to') > 0
替换cdb_posts表的message字段,将“viewthread.?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
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product