批量更新某字段内容的部分内容 replace(要替换的字段,'被替换的字符串,'替换成的字符串')

来源:互联网 发布:霸业传奇宝石升级数据 编辑:程序博客网 时间:2024/06/08 08:52

要求:

一个字段值:

………………预约…………

要将其中 “预约”,改成“预定”。

但是我开始写的时候,写成了

 update ..set smscontent = replace ('预约','预定')

于是悲剧发生了,这些要改的内容,全部改成  “预定'”  了。于是,改回来。

1.先把改错的内容改回原样。

update t_busi_presend_mx mx set mx.smscontent=( select smscontent from t_busi_main_presend2 m2 where mx.mainid=m2.id and m2.id in (select mainidfrom t_busi_presend_mx  where clientid='69772719253482349004' and cjsj>=to_date('2012-05-21','yyyy-mm-dd') and sendstatus='5')) where exists(select 1 from t_busi_presend_mx  twhere t.clientid='69772719253482349004' and t.cjsj>=to_date('2012-05-21','yyyy-mm-dd') and t.sendstatus='5' and t.id=mx.id);  

 

如果掉了最后一个条件,则全表了,就锁了。然后kill session,重新执行了一遍。

2.把内容中“预约”批量更新成“预定”

update t_busi_presend_mx set --sendstatus='1',resendcnt=0,smscontent=replace(smscontent,'预约','预定')where clientid='69772719253482349004' and cjsj>=to_date('2012-05-21','yyyy-mm-dd') and sendstatus='5'