ORACLE UPDATE具有多个值的多行

时间:2015-01-21 17:01:51

标签: oracle

select distinct T1.a1, T2.a1  
from T1, T2, T3 where 
T2.name='Something' and T2.value is not null and
T2.a1=T3.a1 and T1.a2=T3.a2 and 
T1.a3='Something' and T1.a4 is null

我在T2中填充了值,在T1中缺少值。

我必须用T2值更新T1值。 SELECT sql正确地带来了值。但是我无法为ORACLE数据库提供UPDATE sql。

1 个答案:

答案 0 :(得分:1)

尝试使用MERGE:

merge into t1 tgt
using (select distinct t1.a1 t1_a1, t2.a1 t2_a1
       from   t1,
              t2,
              t3
       where  t2.name='Something' 
       and    t2.value is not null
       and    t2.a1=t3.a1
       and    t1.a2=t3.a2
       and    t1.a3='Something'
       and    t1.a4 is null) src
  on (tgt.a1 = src.t1_a1)
when matched then
update set tgt.a1 = src.t2_a1;