1、同一张表操作
使用场景:表数据添加时需要判断是否需要新增,可以减少代码的编写量
MERGE INTO A tagret
USING ( select count(*) ct from source t2 where t2.key='key1' )x
on (x.ct>0)
when matched then
update set a= '123' where id ='1'
when not matched then
insert (a,b) values(1,2)
1、同一张表操作
使用场景:表数据添加时需要判断是否需要新增,可以减少代码的编写量
MERGE INTO A tagret
USING ( select count(*) ct from source t2 where t2.key='key1' )x
on (x.ct>0)
when matched then
update set a= '123' where id ='1'
when not matched then
insert (a,b) values(1,2)