Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 寻找更好的解决方案-合并语句_Oracle_Plsql_Merge - Fatal编程技术网

Oracle 寻找更好的解决方案-合并语句

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

我有两个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
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
中缺少的值由硬编码行中的值填充