我不太明白这个DECODE函数将如何自行解析,特别是在尖头(==>)参数中:
DECODE
(
SH.RESPCODE, 0, SH.AMOUNT-DEVICE_FEE,
102, SH.NEW_AMOUNT-DEVICE_FEE,
==>AMOUNT-DEVICE_FEE,
0
)
提前感谢您对该参数将解决的任何启示。
答案 0 :(得分:3)
它说:
If the value of SH.RESPCODE is 0, then return SH.AMOUNT-DEVICE_FEE.
Otherwise, if it's equal to 102, then return SH.NEW_AMOUNT-DEVICE_FEE.
Otherwise, if it's equal to AMOUNT-DEVICE_FEE, then return 0
作为案例陈述,它将是:
Case SH.RESPCODE
when 0 then SH.AMOUNT-DEVICE_FEE
when 102 then rSH.NEW_AMOUNT-DEVICE_FEE
when AMOUNT-DEVICE_FEE then 0
else null
end
两者之间在处理NULL方面存在一些细微差别。
答案 1 :(得分:2)
在伪代码中,这相当于以下IF语句
IF( sh.respcode = 0 )
THEN
RETURN sh.amount-device_fee
ELSIF( sh.respcode = 102 )
THEN
RETURN sh.new_amount-device_fee
ELSIF( sh.respcode = amount-device_fee )
THEN
RETURN 0;
END IF;
答案 2 :(得分:1)
DECODE
基本上等同于CASE
表达式。
所以这个
DECODE
(
SH.RESPCODE, 0, SH.AMOUNT-DEVICE_FEE,
102, SH.NEW_AMOUNT-DEVICE_FEE,
==>AMOUNT-DEVICE_FEE,
0
)
等同于此
CASE SH.RESPCODE
WHEN 0 THEN SH.AMOUNT - DEVICE_FEE
WHEN 102 THEN SH.NEW_AMOUNT - DEVICE_FEE
WHEN AMOUNT - DEVICE_FEE THEN 0
END
答案 3 :(得分:0)
DECODE
与CASE
相当的评论很好。我发现有用的一件事是格式化DECODE
调用以使其更具可读性,如:
DECODE(SH.RESPCODE,
0, SH.AMOUNT-DEVICE_FEE,
102, SH.NEW_AMOUNT-DEVICE_FEE,
AMOUNT-DEVICE_FEE, 0)
分享并享受。