当在数据库表中查询不到指标数据时,希望显示为0的话:
方式一:select case (SELECT
count(1)
FROM prpseadailycheck pc
where pc.checkcode = 'BDCBL')
when 0 then 0
else
(SELECT
pc.grade
FROM prpseadailycheck pc
where pc.checkcode = 'BDCBL' )
end
from dual;
当有值时,显示某一个字段的值
select case (SELECT count(1)
FROM prpseadailycheck pc where pc.checkcode = 'XZMD')
when 0 then 0
else
(SELECT max(pp.grade) FROM prpseadailycheck pp where pp.checkcode = 'XZMD' )
end
from dual;
方式二:
SELECT nvl( (SELECT pc.grade
FROM prpseadailycheck pc
where pc.checkcode = 'BDCBL'),0) from dual