Oracle 寻找更好的解决方案-合并语句
我有两个merge语句,其中一个使用另一个的行子集。是否有优化解决方案的方法 报表1 报表2 例如 表Oracle 寻找更好的解决方案-合并语句,oracle,plsql,merge,Oracle,Plsql,Merge,我有两个merge语句,其中一个使用另一个的行子集。是否有优化解决方案的方法 报表1 报表2 例如 表 a b c 100 10 null 100 20 null 100 30 null 100 40 null 100 50 null a b c 100 10 99 100 20 88 100 30 77
a b c
100 10 null
100 20 null
100 30 null
100 40 null
100 50 null
a b c
100 10 99
100 20 88
100 30 77
100 40 66
100 50 null
a b c
100 10 99
100 20 88
100 30 77
100 40 66
100 50 99
表B
a b c
100 10 99
100 20 88
100 30 77
100 40 66
第一次合并后
表
a b c
100 10 null
100 20 null
100 30 null
100 40 null
100 50 null
a b c
100 10 99
100 20 88
100 30 77
100 40 66
100 50 null
a b c
100 10 99
100 20 88
100 30 77
100 40 66
100 50 99
第二次合并后
表
a b c
100 10 null
100 20 null
100 30 null
100 40 null
100 50 null
a b c
100 10 99
100 20 88
100 30 77
100 40 66
100 50 null
a b c
100 10 99
100 20 88
100 30 77
100 40 66
100 50 99
第一条语句更新所有必需的行,但表B中没有匹配行的行除外。因此,在第二个merge语句中,我使用表B中某个硬编码行中的另一个值更新该行。我希望,这会有所帮助:
merge into tableA
using (select tt.a, tt.b, b.c
from (select tableA.a, tableA.b, nvl(tableB.b, '10') hardcoded_b
from tableA left join tableB on tableA.a = tableB.a and tableA.b = tableB.b) tt
join tableB b on tt.a = b.a and tt.hardcoded_b = b.b) t
on (tableA.a = t.a and tableA.b = t.b)
when matched then update set tableA.c = t.c;
在子查询
t
中,我创建了一组行,其中表b
中缺少的值由硬编码行中的值填充。我希望这会有帮助:
merge into tableA
using (select tt.a, tt.b, b.c
from (select tableA.a, tableA.b, nvl(tableB.b, '10') hardcoded_b
from tableA left join tableB on tableA.a = tableB.a and tableA.b = tableB.b) tt
join tableB b on tt.a = b.a and tt.hardcoded_b = b.b) t
on (tableA.a = t.a and tableA.b = t.b)
when matched then update set tableA.c = t.c;
在子查询t
中,我创建了一组行,其中表b
中缺少的值由硬编码行中的值填充