![](/img/trans.png)
[英]Oracle SQL Update with Join not using table results for 'set'
[英]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.