【发布时间】:2012-05-11 07:00:11
【问题描述】:
写oracle sql让我头疼。当我的 sql 返回 0 行时,我需要它返回“空”而不是返回 0 行。例如,
select name from employee where id=1;
结果:
0 rows selected
我需要它像这样返回:
Empty
已选择 1 行
既然db中没有这样的记录,有没有办法做到这一点?我确实需要它返回一个值。谢谢!
【问题讨论】:
写oracle sql让我头疼。当我的 sql 返回 0 行时,我需要它返回“空”而不是返回 0 行。例如,
select name from employee where id=1;
结果:
0 rows selected
我需要它像这样返回:
Empty
已选择 1 行
既然db中没有这样的记录,有没有办法做到这一点?我确实需要它返回一个值。谢谢!
【问题讨论】:
更新
SELECT NVL((select name from employee where id=1), 'Empty') name from dual
感谢@Samual 的想法!!
【讨论】:
select name
from employee
where id=1
union all
select 'Empty'
from dual
where not exists (select 1 from employee where id=1)
【讨论】: