数据库 ORACLE 9Icomp表中有这么一个字段 comp_licence,String类型,主键COMP_ID,内容形式为:“客420822100001”。条件查询下有5000条记录客户要求将其中的数字的前六位420822全部修改为 421321,后六位从101001开始叠加生成。例如 客420822100001 就要修改成 客421321101001;客420822100002 就要修改成 客421321101002。各位大侠帮帮忙?这个情况可以怎么解决?

解决方案 »

  1.   

    -- 闲一步到位麻烦的话,用中间表去更新:-- Step 1: 创建临时表:
    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;
      

  2.   

    update shixw set id=('客421321'||(rownum+101000)) where rownum<5000
      

  3.   

    update tt set id = '客421321' || substr(id,8,length(id)) 
     where substr(id,2,6) ='420822'