表中有一字段:object_id
因为该字段的记录出错,需修改更新,举其中一个记录为例,表中记录为:10-002-2010-2135,正确应该是:10-123-2010-2135即是说,字段中记录002都需改为123,update 语句如何写...

解决方案 »

  1.   

    update table t set t.object_id=substr(t.object_id,1,3)||'123'||substr(t.object_id,7)
    where t.object_id='10-002-2010-2135'
      

  2.   

    update table t set t.object_id=substr(t.object_id,1,3)||'123'||substr(t.object_id,7)
    where substr(t.object_id,4,3)='002'
      

  3.   

    -----如此简单呵呵。
    update table t
       set t.object_id = '10-123-2010-2135'
     where t.object_id = '10-002-2010-2135';
      

  4.   

    如果多的话为什么不用replace(str,str1,str2);呢
      

  5.   

    update #T set object_id = replace(object_id,'-002-','-123-')
      

  6.   

    --如果位置不固定的话,replace函数简洁,如果情况很复杂,用正则不错
    update t set object_id = regexp_replace(object_id,'-002-','-123-');
      

  7.   


    update tb set object_id=replace(object_id,'-002-','-123-')
      

  8.   

    呵呵,如果是位置固定的话用replace不能保证只更新4-6位.正则好像可以做到,不过我写不出来
      

  9.   

    select replace(a,'002','123') from aa where a like '%002%'
      

  10.   

    update aa set a = replace(a,'002','123') where a like '%002%';