伪代码如下:
if exists (
select key_field
from table_name
where key_field = new_key_value
) then
delete from table_name
end if
insert into table_name (key_field, field2, field3, ...)
select new_key_value, value2, value3, ...
你可以用merge into
merge into tableA using (select * from dual) as tableB on (tableA.id=tableB.id)
when matched then update set ...
when not matched then insert value()
if exists(SQL语句)
begin
操作语句
end