簡體   English   中英

Null 除法時出錯,但溢出時分子和分母運行正常

[英]Null error when dividing, but numerator and denominator runs fine when spilt up

這可能有一個非常明顯的答案,但我無法弄清楚為什么它會出錯:

(sum(case when N.DOS_DURATION <= 3 then N.NURA_Claims else 0 end)/sum(case when N.DOS_DURATION <= 3 then N.SRD_Prem else 0 end)) as NURA_MBR_Q1

ERROR [2:1]:(SQLSTATE: 42911, SQLCODE: -419): DB2 SQL Error: SQLCODE=-419, SQLSTATE=42911, SQLERRMC=null, DRIVER=4.25.13
ERROR [2:1]:(SQLSTATE: 56098, SQLCODE: -727): DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-419;42911;, DRIVER=4.25.13

但是,拆分分子和分母運行良好,並且沒有 null 或 0 值。

sum(case when N.DOS_DURATION <= 3 then N.NURA_Claims else 0 end) as Claims, 
sum(case when N.DOS_DURATION <= 3 then N.SRD_Prem else 0 end) as Premiums

我被難住了? 有什么建議么? 分子和分母 output

該錯誤與表達式鏈接中描述的規則有關。 查看Decimal arithmetic in SQLTable 4. Precision and scale of the result of a decimal division
您可以使用dec_arithmetic數據庫配置參數或使用數據類型轉換來解決問題。
下面是一個示例,當dec_arithmetic設置為其默認值時。

SELECT
  -- Wrong - negative precision:
  -- 31 - p + s - s' = 31 - 31 + 2 - 3 = -1
  -- You get the same error as in the question.
  --NURA_Claims / SRD_Prem

  -- Correct - we achieve the desired precision with 
  -- data type casting for one of the operands
  -- 31 - p + s - s' = 31 - 31 + 5 - 3 = 2
  DEC (NURA_Claims, 31, 5) / SRD_Prem
FROM (VALUES (DEC (2, 31, 2), DEC (1, 31, 3))) N (NURA_Claims, SRD_Prem)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM