oracle Greatest与decode及sign的使用

GREATEST(0,(summary.sub_cash_max_withdraw + pkg_equ_margin_value.sf_max_withdraw(summary.comp_grp_id, summary.account_id, summary.sub_account_id, summary.trading_account_id)
-ABS(DECODE(SIGN(summary.dividend_Entl),-1,summary.dividend_Entl,0,0,1,0))))as max_withdraw_amt

用sign()可以判断这表值大于0还是小于0,还是等于0,然后用decode根据sign返回的结果作相应处理。

而greatest函数则是取值中的最大值,上面则是将后面的结果与0比较,取较大值。

猜你喜欢

转载自aniyo.iteye.com/blog/2112507