长期不写SQL后经常容易忘记,免得再次Baidu,写个简单例子方便查阅。
with
T1 as (select A from Table1),
T2 as (select A from Table2 where not exists (select A from T1 where rownum=1))
select * from T1
union all
select * from T2
union all
select 'no records' from dual
where not exists (select A from T1 where rownum=1)
and not exists (select A from T2 where rownum=1);