【发布时间】:2020-08-24 11:14:41
【问题描述】:
我有 2 个表,比如说 'ACCESSENTRY' 和 PROJECT 。PROJECT 包含列 ROLE、ACCESSENTRY。我需要找到 ACCESSENTRY 等于 'A' 的第一行,并将这些行插入到 ACCESSENTRY 新行中并获取 'ROLE' 并给出 ACCESSENTRY ,但如果该行不存在。
所以让我们在这个查询中说:
【问题讨论】:
标签: sql oracle sql-insert
我有 2 个表,比如说 'ACCESSENTRY' 和 PROJECT 。PROJECT 包含列 ROLE、ACCESSENTRY。我需要找到 ACCESSENTRY 等于 'A' 的第一行,并将这些行插入到 ACCESSENTRY 新行中并获取 'ROLE' 并给出 ACCESSENTRY ,但如果该行不存在。
所以让我们在这个查询中说:
【问题讨论】:
标签: sql oracle sql-insert
您可以将INSERT ... SELECT 与NOT EXISTS 一起使用:
insert into UM_ACCESSENTRY(role, accessentry)
select p.role, 'test'
from UM_PROJECT p
where p.PROJECT='ProjectName'
and not exists (
select 1 from UM_ACCESSENTRY a
where a.role = p.role and a.accessentry = 'test'
)
【讨论】:
我想你想要not exists:
insert into ROLEE (role, accessentry)
select r.role, 'ACCESS'
from ROLEE r
where r.ACCESSENTRY = 'A' and
not exists (select 1 from rolee r2 where r2.role = r.role and r2.column2 = 'ACCESS');
【讨论】: