繁体   English   中英

oracle db - 如果 join 没有结果则更新表

[英]oracle db - update table if join has no results

在 MS SQL 中,我可以执行以下操作:

if not exists (select * 
from table_1
inner join table_2 on table_1.id = table_2.id
where table_1.y = 200 and table_2.x =5)
begin
insert into table_1  values (200,1000)
insert into table_2 values (5,1000)
end;

我可以在 Oracle DB 中做这样的事情吗?

一种方法是使用变量来检查您需要的任何内容,然后决定要做什么; 例如:

declare
  vCheck   number;
begin
  select count(*)
  into vCheck
  from ...
  where ...;
  --
  if vCheck = 0 then
    insert ...;
    insert ...;
  end if;
end;

您可以使用一个或多个变量,具体取决于您需要执行的检查,然后调整IF条件以实现更复杂的逻辑。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM