日期:2014-05-16  浏览次数:20617 次

oracle sum null值相关 null 和 空字符串('')

组函数不计算null值

?


SELECT SUM(a) FROM ( SELECT 1 a FROM dual UNION SELECT 2 a FROM dual UNION SELECT 3 a FROM dual );

?结果是6

?

?

?

?

SELECT SUM(a) FROM (
  SELECT 1 a FROM dual
  UNION
  SELECT 2 a FROM dual
  UNION
  SELECT 3 a FROM dual
  UNION
  SELECT NULL a FROM dual
);

??结果还是6

?

?

?

例如:http://blog.itpub.net/23650854/viewspace-684335

select rownum,a from t_null;

??? ROWNUM????????? A
---------- ----------
???????? 1
???????? 2
???????? 3

z@test10gr2> select sum(a) from t_null;

??? SUM(A)
----------

? ? NULL

?

select rownum,a from t_null;
    ROWNUM          A
---------- ----------
         1
         2
         3
         4         77

select sum(a) from t_null;
    SUM(A)
----------
        77

?

?

?

?

?

?