ORACLE数据库有数据就更新没有就插入怎么做?

2024-10-31 21:35:53
推荐回答(1个)
回答(1):

1,
if 1>0
then
insert into TEST (ID,NAME) VALUES (1,'AA');
else
update TEST set NAME='BB' where ID=1;
end if

2.
begin
update TEST set NAME='BB' where ID=1;

if sql%notfound then
insert into TEST (ID,NAME) VALUES (1,'AA');
end if;
end;

3.MERGER 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');