Можно ли использовать ВСТАВКУ И ОБНОВЛЕНИЕ на When matched then
? ? Я видел в Интернете, что это возможно, поэтому мой вопрос: как я могу сделать что-то вроде ниже?
create table target_table(a, b, c, d, e) as (
select 1, 2, 'NO', 100,'MDE' from dual union all
select 1, 3, 'NO', 100,'AGC' from dual union all
select 1, 4, 'NO', 100,'MDE' from dual union all
select 1, 6, 'YES', 100,'MDE' from dual union all
select 1, 5, 'NO', 100,'MDE' from dual );
create table source_table(a, b, c, d, e) as (
select 1, 0, 'NO', 200,'AGC' from dual union all
select 1, 1, 'NO', 200,'MDE' from dual union all
select 1, 3, 'YES', 200,'AGC' from dual union all
select 1, 4, 'NO', 200,'MDE' from dual union all
select 1, 5, 'YES', 200,'MDE' from dual );
merge into target_table t
using source_table s
on (t.a = s.a and t.b = s.b)
when matched then
case
when t.c = 'NO' and s.c = 'YES' and t.e = 'MDE' and s.e = 'MDE' then update set t.d = s.d, t.c = s.c
when t.e <> 'MDE' and s.e <> 'MDE' then insert values (s.a, s.b, s.c, s.d, s.e)
end
when not matched then insert values (s.a, s.b, s.c, s.d, s.e);