简体   繁体   中英

oracle db - update table if join has no results

In MS SQL I can do something like this:

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;

Can I do something like this in Oracle DB ?

One way could be by using variables to check whatever you need and then decide what to do; for example:

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

You can use one or more variables, depending on the check you need to do, and then adapt the IF condition to implement more complex logics.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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