数据库 ORACLE 9Icomp表中有这么一个字段 comp_licence,String类型,主键COMP_ID,内容形式为:“客420822100001”。条件查询下有5000条记录客户要求将其中的数字的前六位420822全部修改为 421321,后六位从101001开始叠加生成。例如 客420822100001 就要修改成 客421321101001;客420822100002 就要修改成 客421321101002。各位大侠帮帮忙?这个情况可以怎么解决?
调试欢乐多
create table comp_tmp
as
select comp_id, '客421321'||to_char(10100+(row_number() over(order by comp_id))) as cid
from comp
where ...;-- Step 2: 更新:
update comp t1
set t1.compid=(select t2.cid from comp_tmp t2 where t2.compid=t1.compid)
where exists (select 1 from comp_tmp t3 where t3.compid=t1.compid);-- Step 3: 删除中间表:
drop table comp_tmp purge;
where substr(id,2,6) ='420822'