[英]oracle db - update table if join has no results
In MS SQL I can do something like this:在 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;
Can I do something like this in Oracle DB ?我可以在 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.您可以使用一个或多个变量,具体取决于您需要执行的检查,然后调整IF
条件以实现更复杂的逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.