sql - 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 中做这样的事情吗?
解决方案
一种方法是使用变量来检查您需要的任何内容,然后决定要做什么;例如:
declare
vCheck number;
begin
select count(*)
into vCheck
from ...
where ...;
--
if vCheck = 0 then
insert ...;
insert ...;
end if;
end;
您可以使用一个或多个变量,具体取决于您需要执行的检查,然后调整IF
条件以实现更复杂的逻辑。
推荐阅读
- c++ - 浮点数是否以 0.5 结尾。C++
- java - 在 Web 控制台以外的地方访问 H2 嵌入式数据库?
- scala - Spark - 给定单词后出现频率最高的单词
- python - 如何在 Python 中使用 Kerberos 库?
- ruby-on-rails - Ruby on Rails:使用 ransack 在日期范围之间进行查询
- python - 通过Python中的离散点计算斜率
- javascript - 即使在导航到另一个页面后,如何保持网站内容的翻译?(ember.js ember-i18n)
- go - Goroutines 内存泄漏
- javascript - SSMS 列名无效
- css - 使用视口高度会导致某些屏幕尺寸的某些部分出现像素线