Gar*_*ary 2 sql oracle10g oracle11g
我在编写oracle sql时遇到了麻烦.当我的sql返回0行时,我需要它返回"empty"而不是返回0行.例如,
select name from employee where id=1;
Run Code Online (Sandbox Code Playgroud)
结果:
0 rows selected
Run Code Online (Sandbox Code Playgroud)
我需要它像这样返回:
Empty
Run Code Online (Sandbox Code Playgroud)
选择了1行
由于db中没有这样的记录,有没有办法做到这一点?我确实需要它返回一个值.谢谢!
select name
from employee
where id=1
union all
select 'Empty'
from dual
where not exists (select 1 from employee where id=1)
Run Code Online (Sandbox Code Playgroud)