表1数据:ID        CODE             PRIC
1 11061CJ70B 1.00
2 11110CJ70A 1.00
3 11110ED50A 1.00
4 11150CJ70A 1.00
5 11220JN01A 1.00
6 11227JN00B 1.00
7 11332JN01B 1.00
8 11332JN31A 1.00
9 11710ED50C 1.00表2数据:ID        CODE              PRIC
          1        11061CJ70B         12.19
          2        11110CJ70A          2.29
          3        11110ED50A         2.41
          4        11150CJ70A          1.06
          5        11220JN01A          19.63
          6        11227JN00B          3.18把表2的PRIC数据更新到对应的表1中,条件是表2的CODE = 表1的CODE
也就是说把表2里的pric(价格)更新到对应的表1的CODE(编码)上。请大家帮吗

解决方案 »

  1.   

    -- 如果 t2.proc 唯一,可以将 distinct 去掉
    udate tb1 t1
    set t1.proc=(select distinct t2.proc from tb2 t2 where t2.code=t1.code)
    where exists ( select 1 from tb1 t3 where t3.code=t1.code);
      

  2.   

    udate tb1 t1
    set t1.proc=(select t2.pric from tb2 t2 where t2.code=t1.code)
    where exists ( select 1 from tb1 t3 where t3.code=t1.code);
      

  3.   

    update table1 
    set pric = (select pric from table2 where code = table1.code and rownum = 1)
    where exists (select 1 from table2 where code = table1.code);
      

  4.   

    你把表1里存在,而表2里不存在的数据更新为null了,所以不行
      

  5.   

    update 表1 a set price(select price from 表2 b where a.code=b.code )--merge into
    merge into 表1 a using 表2 b on(a.code=b.code)
    when matched then update set a.price=b.price 
      

  6.   

    merge 吧merge 吧,考虑哈merge into 语法...
      

  7.   

    --1.update..set..select
    update t1
       set pric = (select pric from t2 where t1.code = t2.code)
     where exists (select 1 from t2 where t1.code = t2.code);
     
    --2.merge into
    merge into t1
    using t2
    on (t1.code = t2.code)
    when matched then
      update set t1.pric = t2.pric;
      
    --3.update..select..set
    update /*+bypass_ujvc*/ (select t1.pric pric1, t2.pric pric2
            from t1, t2
           where t1.code = t2.code)
       set pric1 = pric2;
      

  8.   

    update 
         (select t1.pric pric1, t2.pric pric2
            from t1 inner join t2 on t1.code = t2.code)
       set pric1 = pric2