Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对编写 oracle sql 感到头疼。当我的 sql 返回 0 行时,我需要它返回“空”而不是返回 0 行。例如,
select name from employee where id=1;
结果:
0 rows selected
我需要它像这样返回:
Empty
已选择 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)
更新
SELECT NVL((select name from employee where id=1), 'Empty') name from dual
感谢@Samual 的想法!!