如何在查询中引用参数选择?
How to reference parameter selection in query?
现在我有一个查询显示基于为 'role' 选择的值参数列表的结果:
select distinct
i.control
,i.role
,i.entitlement
from ctrl_access_incident i
where i.role in nvl(:rolelov, i.role)
我想添加到查询中,以根据所选的角色参数提取所有冲突的角色——因此所有与所选参数具有相同控件的角色。如何引用选定的参数值?
您可以使用 IN
或 INNER JOIN
,如下所示:
SELECT DISTINCT
CONTROL,
ROLE,
ENTITLEMENT FROM
ctrl_access_incident
WHERE CONTROL IN
(select distinct i.CONTROL
from ctrl_access_incident i
where (:rolelov is null or i.role= :rolelov))
或
SELECT DISTINCT
C1.CONTROL,
C1.ROLE,
C1.ENTITLEMENT FROM
ctrl_access_incident C1
JOIN ctrl_access_incident C2
ON (C1.CONTROL = C2.CONTROL)
WHERE (:rolelov is null or C2.role= :rolelov)
干杯!!
现在我有一个查询显示基于为 'role' 选择的值参数列表的结果:
select distinct
i.control
,i.role
,i.entitlement
from ctrl_access_incident i
where i.role in nvl(:rolelov, i.role)
我想添加到查询中,以根据所选的角色参数提取所有冲突的角色——因此所有与所选参数具有相同控件的角色。如何引用选定的参数值?
您可以使用 IN
或 INNER JOIN
,如下所示:
SELECT DISTINCT
CONTROL,
ROLE,
ENTITLEMENT FROM
ctrl_access_incident
WHERE CONTROL IN
(select distinct i.CONTROL
from ctrl_access_incident i
where (:rolelov is null or i.role= :rolelov))
或
SELECT DISTINCT
C1.CONTROL,
C1.ROLE,
C1.ENTITLEMENT FROM
ctrl_access_incident C1
JOIN ctrl_access_incident C2
ON (C1.CONTROL = C2.CONTROL)
WHERE (:rolelov is null or C2.role= :rolelov)
干杯!!