以下查询如何在oracle数据库中处理,我在Toad中尝试
Query1 - SELECT T_BASIS_ACCESS_ID FROM ECKERNEL_MCA.T_BASIS_ACCESS WHERE ROLE_ID LIKE 'MCA.GFS.LEAD'
Query2 - SELECT OBJECT_ID, NAME FROM ECKERNEL_MCA.OV_AREA WHERE END_DATE IS NULL AND OBJECT_ID IN
(SELECT DISTINCT REPLACE(REPLACE(REPLACE(ATTRIBUTE_TEXT, '(', '' ),')',''), '''', '')
FROM ECKERNEL_MCA.T_BASIS_OBJECT_PARTITION WHERE T_BASIS_ACCESS_ID IN
(SELECT T_BASIS_ACCESS_ID FROM ECKERNEL_MCA.T_BASIS_ACCESS WHERE ROLE_ID LIKE 'MCA.GFS.LEAD') )
Query3 - SELECT OBJECT_ID, NAME FROM ECKERNEL_MCA.OV_AREA WHERE END_DATE IS NULL
答案 0 :(得分:0)
试一试。它应该按照您在评论中指明的方式行事。
我想如果Query1从表中返回任何结果,比如 如果记录为零,则记录数为1+然后执行Query2 如果(Query1> 0)执行Query2,则执行查询3,否则执行Query3
--Query 1
with Q_1 as
(SELECT T_BASIS_ACCESS_ID FROM ECKERNEL_MCA.T_BASIS_ACCESS WHERE ROLE_ID LIKE 'MCA.GFS.LEAD')
--Query 2
SELECT OBJECT_ID, NAME FROM ECKERNEL_MCA.OV_AREA WHERE END_DATE IS NULL AND OBJECT_ID IN
(SELECT DISTINCT REPLACE(REPLACE(REPLACE(ATTRIBUTE_TEXT, '(', '' ),')',''), '''', '')
FROM ECKERNEL_MCA.T_BASIS_OBJECT_PARTITION WHERE T_BASIS_ACCESS_ID IN
(SELECT T_BASIS_ACCESS_ID FROM ECKERNEL_MCA.T_BASIS_ACCESS WHERE ROLE_ID LIKE 'MCA.GFS.LEAD') )
--If Query 1 returns anything
WHERE EXISTS (SELECT 1 FROM Q_1)
UNION ALL
--Query 3
SELECT OBJECT_ID, NAME FROM ECKERNEL_MCA.OV_AREA WHERE END_DATE IS NULL
--If Query 1 returns nothing
WHERE NOT EXISTS (SELECT 1 FROM Q_1)