Why SUM(null) is not 0 in Oracle?

前端 未结 6 1971
轻奢々
轻奢々 2021-01-04 08:33

It would be appreciated explaining the internal functionality of SUM function in Oracle, when encountering null values:
The result of

select sum(null)          


        
6条回答
  •  独厮守ぢ
    2021-01-04 08:46

    As Bohemian has pointed out, both SUM and AVG exclude entries with NULL in them. Those entries do not go into the aggregate. If AVG treated NULL entries as zero, it would bias the result towards zero.

    It may appear to the casual observer as though SUM is treating NULL entries as zero. It's really excluding them. If all the entries are excluded, the result is no value at all, which is NULL. Your example illustrates this.

提交回复
热议问题