首页 > 解决方案 > oracle db - 如果连接没有结果,则更新表

问题描述

在 MS SQL 中,我可以这样做:

如果不存在(选择 *
从表_1
table_1.id 上的内连接 table_2 = table_2.id
其中 table_1.y = 200 和 table_2.x =5)
开始
插入 table_1 值 (200,1000)
插入 table_2 值 (5,1000)
结尾;

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

标签: sqloracle

解决方案


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

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

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


推荐阅读