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');


 

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