create table table1 (id number, text varchar2(20));
create table table2 (id number, text varchar2(20), text2 varchar2(20));
insert into table1 values (1,'');
insert into table1 values (2,'');
insert into table1 values (3,'');
insert into table2 values (1,'a','b');
insert into table2 values (2,'a','b');
insert into table2 values (3,'a','b');
insert into table2 values (4,'a','b');
Я понимаю, что вы хотите получить что-то вроде кода ниже с комментариями линии
merge into table1 t1
using table2 t2
on (t1.id = t2.id)
when matched then update set
t1.text = t2.text where t1.id = 1
--t1.text = t2.text2 where t1.id = 2
when not matched then insert values (t2.id, t2.text);
Я бы сделать это так:
merge into table1 t1
using (select id, case id when 1 then text when 2 then text2 else null end as tt, text from table2) t2
on (t1.id = t2.id)
when matched then update set
t1.text = t2.tt where t2.tt is not null
--t1.text = t2.text2 where t1.id = 2
when not matched then insert values (t2.id, t2.text);
select * from table1;
В [документации] (http://docs.oracle .com/database/121/SQLRF/statements_9016.htm # SQLRF01606) – Aleksej
, вы можете иметь только одну часть «при сопоставлении» в оракуле, но вы можете определить несколько логических условий в разделе «ON», связанное с оператором «OR» – schurik
Вы также можете использовать предложение where в разделе обновления, чтобы указать условие – Kacper