Oracle数据库查询表中记录为空,Empty result set fetched

Oracle数据库查询表中记录为空,Empty result set fetched,此时没有数据,获取不到任何值,但是此时我们需要根据结果来做计算,因此可以使用count()函数来做结果统计,将统计结果用来做判断。

场景:需要查询出结果用于求和计算,没有结果时取0。
方案:使用case...when做sql的条件判断,当有结果为1时表示有记录,此时使用查询到的记录,当结果是其他时表示没有记录,此时count()统计数据为0,用统计结果做结果返回用于求和运算;

sql如下:

select count(1) from ldsysvar where sysvar='onerow' and ((
select Mult*50 from lspol where contno='?ContNo?' and riskcode='00963000'
)+(
(
case (select count(STANDBYFLAG1*100) from lspol where contno='?ContNo?' and riskcode in ('00958100') )
when 1 then (select STANDBYFLAG1*100 from lspol where contno='?ContNo?' and riskcode in ('00958100'))
else (select count(STANDBYFLAG1*100) from lspol where contno='?ContNo?' and riskcode in ('00958100') )
end
)
))>500 and '?RiskCode?' in ('00963000','00554000');


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章