返回sql中的默认行

Vij*_*jay 5 sql unix oracle

如果没有找到行,是否可以在oracle sql中返回默认行.我有一个进程,其中获取的行将放在一个平坦的ascii文件中.现在我要求如果sql查询没有提取任何行,那么ascii文件中应该有一个默认行.

如果查询注释没有提取任何行,则sql中是否可以输出默认行:我不想使用pl/sql.

Eri*_*ler 6

您可以使用UNION ALL:

select a, b, c from foobar 
where foo='FOO'
union all
select 'def', 'ault', 'value' from dual 
where not exists ( select 'x' from foobar where foo='FOO' )
Run Code Online (Sandbox Code Playgroud)


Dav*_*dge 6

对于复杂查询,其中查找结果集中是否存在行的开销是繁重的还是查询非常庞大且难以处理,那么子查询因子子句可能是有益的:

With my_query as
    (
    select a, b, c from foobar where foo='FOO' 
    )
Select a,b,c
From   my_query
Union All
Select ...
From   dual
Where  Not Exists
       (Select 1 from my_query)
/
Run Code Online (Sandbox Code Playgroud)