sql - Why SUM(null) is not 0 in Oracle? -
it appreciated explaining internal functionality of sum function in oracle, when encountering null values:
result of
select sum(null) dual; null
but when null value in sequence of values (like sum of null-able column), calculated value of null value 0
select sum(value) ( select case when mod(level , 2) = 0 null else level end value dual connect level <= 10 ) 25
this more interesting when seeing result of
select (1 + null) dual null
as operation null result null (except is null
operator).
==========================
some update due comments:
create table odd_table select sum(null) some_name dual;
will result:
create table odd_table ( some_name number )
why some_name
column of type number?
sql not treat null
values zeros when calculating sum
, ignores them:
returns sum of values, or
distinct
values, in expression. null values ignored.
this makes difference in 1 case - when sequence being totalled not contain numeric items, null
s: if @ least 1 number present, result going numeric.
Comments
Post a Comment