例如:
select from A a where a.codetype not in (select code from B b where b.codetypedesc=‘出险人保单身份类型代码‘;
改为:
select from A a where a.codetype not in (select code from B b where b.codetypedesc=‘C001‘;
有的人觉得直接用replace替换:
update A set ori_sql = (select replace(lower(a.ori_sql),‘出险人保单身份类型代码‘,‘C001‘) from A) ;
当时我也尝试了,但是A表中有上千万的数据,自然where条件不单单是‘出险人保单身份类型代码‘这一个条件,我对where条件存在的代码去重还有一千多条结果,这就意味着我要跑replace上述的sql一千多遍,我就会疯掉的。后来我尝试了将excel里的编码插入到表A,列名为r_code,将A表中where条件单独取出作为一列r_cow,这样就可以仅用一句sql语句就能实现上千条的不同条件的批量替换字符串中的某个字符了,
sql如下:
update A a set a.ori_sql = (select distinct replace(lower(a1.ori_sql),a1.r_cow,a1.r_code) from A a1 where a.ru_code=a1.row_code);
成功完成,不用加班咯!
原文:https://blog.51cto.com/12777507/2400814