oracle如果 sum为null记为0

oracle如果 sum为null记为0

https://blog.csdn.net/ideality_hunter/article/details/70770320

oracle在使用sum函数计算式会遇到这样的情况。

如果sum的值为null,则什么都不显示。想要如果为null,则显示为0,怎么办?

方法1:

select when sum(t.money) is null then    0    else    sum(t.money) from Money t

 

方法2:

 

NVL(Expr1,Expr2)如果Expr1为NULL,返回Expr2的值,否则返回Expr1的值

例如:select NVL(SUM(MONEY) ,0) from tb全都在NVL这儿起作用

select    NVL(SUM(t.money) ,0)  from Money t

 

posted @ 2018-05-28 16:17  wjj1013  阅读(5465)  评论(0编辑  收藏  举报