ORACLE数据库有数据就更新没有就插入怎么做?
if1>0theninsertintoTEST(ID,NAME)VALUES(1,'AA')elseupdateTESTsetNAME='BB'whereID=1endi...
if 1>0
then
insert into TEST (ID,NAME) VALUES (1,'AA')
else
update TEST set NAME='BB' where ID=1
end if
这么写不可以吗?总是报错!用MERGER如何写? 展开
then
insert into TEST (ID,NAME) VALUES (1,'AA')
else
update TEST set NAME='BB' where ID=1
end if
这么写不可以吗?总是报错!用MERGER如何写? 展开
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');
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');
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询