两张表A(aaa,bbb),B(ccc,ddd) aaa,ccc可以关联,把bbb字段更新到ddd字段里
求一条Oracle 语句

解决方案 »

  1.   

    update A a set a.bbb=
    (select b.ddd from B b where a.aaa=b.ccc);
      

  2.   

    update A a set a.bbb=
    (select b.ddd from B b where a.aaa=b.ccc);
      

  3.   

    这样不好,A表里有,B表没有的字段,都更新为空了,也破环了A不符合条件的数据
      

  4.   

    update b a set b.ddd=(select a.bbb from a where a.aaa=b.ccc);
      

  5.   


    merge into b
    using a
    on (a.aaa = b.ccc)
    when matched then
    update set b.ddd = a.bbb;
      

  6.   


     update B set B.ddd=( 
      select A.bbb from A  where A.aaa=B.ccc) 
    where exists( 
      select 1 from A where A.aaa=B.ccc);
      

  7.   

    update B t
       set t.ddd = (select s.bbb from A s where t.ccc = s.aaa)
     where exists (select 1 from A s where t.ccc = s.aaa);
      

  8.   

    update A a set a.bbb=
    (select b.ddd from B b where a.aaa=b.ccc);
      

  9.   

    两张表A(aaa,bbb),B(ccc,ddd) aaa,ccc可以关联,把bbb字段更新到ddd字段里
    求一条Oracle 语句update b
    set ddd = (select bbb from a where a.aaa = b.ccc and rownum <=1)
    where exists
    (select 1 from a where a.aaa = b.ccc);
      

  10.   


    ORA-30926:无法在源表中获得一组稳定的行
    在更新数据出现 这个错误
      

  11.   


    六楼的是对的。ORACLE的UPDATE语句一定要加EXISTS子句,否则会把B表的所有记录都UPDATE。
      

  12.   

    相应a表里的记录不唯一。加上distinct试试,要是不行就是你需求有问题了
      

  13.   

    如果没有exists或in子句限定范围,那么B表中未有匹配A表 的记录的ddd值将被更新为空
      

  14.   

    樓主,按照你的需求,A.aaa應該是唯一的吧。如果A中有兩條aaa相同的紀錄,如
    aaa bbb
    1   2222
    1   3333
    那,用bbb更新B表,到底用2222還是3333呢?請把表結構列出來看看