欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle两张表关联批量更新其中一张表的数据

程序员文章站 2022-04-03 20:35:28
方法一(推荐): update 表2 set 表2.c = (select b from 表1 where 表1....

方法一(推荐):

update 表2
  set 表2.c =
     (select b
       from 表1
      where 表1.a = 表2.a)
 where exists
     (select 1
       from 表1
      where 表1.a = 表2.a);

尤其注意最后的外层where条件尤为重要,是锁定其批量更新数据的范围。

方法二:

merge into 表2
   using 表1
    on (表2.a = 表1.a)                    -- 条件是 a 相同
when matched
then
  update set 表2.c = 表1.b                   -- 匹配的时候,更新

以上所述是小编给大家介绍的oracle两张表关联批量更新其中一张表的数据,希望对大家有所帮助