我有这样的查询:
select data_name
into v_name
from data_table
where data_table.type = v_t_id
通常,此查询应该只返回一行.当v_t_id上没有匹配项时,程序将失败并显示“No data found”异常.
我知道我可以在PL / sql中处理这个问题,但我想知道是否有办法只在查询中执行此操作.作为测试,我尝试过:
select case
when subq.data_name is null then
'UNKNOWN'
else
subq.data_name
end
from (select data_name
from data_table
where data_table.type = '53' /*53 does not exist,will result in 0 rows. Need fix this...*/
) subq;
…但这显然不起作用(因为subq为空与subq.data_name不相同).这甚至是可能的还是我应该检查我的PL / sql解决方案?
(oracle 10g)