Why SUM(null) is not 0 in Oracle?

前端 未结 6 1986
轻奢々
轻奢々 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 09:03

    SQL does not treat NULL values as zeros when calculating SUM, it ignores them:

    Returns the sum of all the values, or only the DISTINCT values, in the expression. Null values are ignored.

    This makes a difference only in one case - when the sequence being totalled up does not contain numeric items, only NULLs: if at least one number is present, the result is going to be numeric.

提交回复
热议问题