开发者

Multiple Oracle Query

I have 2 sql's (each sql is about 10 lines joining ab开发者_开发问答out 5 tables). These 2 sqls returns same column. I want to execute sql2 only if sql1 returns no result.

How to do this in one sql?


query1
UNION ALL
( query2
   WHERE NOT EXIST (query1)
)

In Oracle you can also factor:

WITH conditional_query AS (query1)
SELECT * FROM conditional_query
UNION ALL
( query2 WHERE NOT EXIST (SELECT NULL FROM conditional_query) )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜