1.这个看不懂第一行的 if (这么查询失败,无效sql)
if 1>0
then
insert into 表名(ID,NAME) VALUES (1,'AA');
else
update 表名 set NAME='BB' where ID=1;
end if
2.这个好理解
begin
update 表名 set NAME='BB' where ID=1;
if sql%notfound then
insert into 表名(ID,NAME) VALUES (1,'AA');
end if;
end;
3.这个复制表数据适用
MERGE into TEST a using (select * from TEST) b on (a.id = b.id)
when matched then //如果
update TEST set NAME='BB'
when not matched then
nsert into TEST (ID,NAME) VALUES (1,'AA');
附带一条查询若没有插入的sql
insert
when
(not exists
(select e.* from 表名 e where e.id ='aaaaaaaaa')
) then
into 表名(id,name) select 'aaaaaaaaa' ,'1111' from dual