作用:对于数据表中的数据,有就修改,没有就添加
原表
ID | NAME |
1 | 张三 |
2 | 李四 |
merge into "TESTMERGE" t1 using (select '1' as "ID",'张三三' as "NAME" from dual) t2 on (t1."ID" = t2."ID")
when matched then
update set t1."NAME" = t2."NAME"
when not matched then
insert ("ID","NAME") values (t2."ID",t2."NAME")
相当于把要插入或者修改的数据放到了虚表中,有此ID,就修改;没有次此ID,就新增;
结果:
ID | NAME |
1 | 张三三 |
2 | 李四 |