update table1 a set a.type = (select type from table2 where type = substr(a.type,1,1))

解决方案 »

  1.   

    update table1 a set type=nvl((select name from table2 where type = substr(a.type,1,1)),type)
      

  2.   

    如果仅仅是第一个字符相同更新那么,nvl防止没有找到记录时也更新
    update table1 a set type=nvl((select name from table2 where type = substr(a.type,1,1)),type)如果是在table1中type有找到table2中的type就更新那么,
    update table1 a set type=nvl((select name from table2 where instr(a.type,type)>0),type)
      

  3.   

    谢谢各位,不过有一点我可能没说清楚,就是有可能不是就第一个字符,象这样substr(a.type,1,1)),type),就不行。有可能是好几个字符的。谢谢
      

  4.   

    如果table2里的type为t1、t13等,也能更新,不仅仅像象这样substr(a.type,1,1)),type)这样,就好比like t1% 这个一样。请问该如何写,多谢
      

  5.   

    to: YuriOU()
    请问nv1是什么意思啊
      

  6.   

    nvl(col,vol)就是 if col is null then nvl(col,vol) = vol
      

  7.   

    update table1 a set a.type=(select b.name from table2 b where instr(a.type,b.type)=1)
    where exists (select 1 from table2 b where instr(a.type,b.type)=1);或者update table1 a set a.type=(select b.name from table2 b where a.type like b.type||'%')
    where exists (select 1 from table2 b where a.type like b.type||'%');
      

  8.   

    还有一个问题,匹配上的按上述方法更新,如果有匹配不上的,我想把table1的type更新成其他,请问各位怎么写。十分感谢
      

  9.   

    update table1 a set type=nvl((select name from table2 where type = substr(a.type,1,1)),'其他')
      

  10.   

    to:ljian_mail(外星人) 
    如果这样写的话,不就全替换成“其他”了吗?