<legend id='7d5j3'><style id='7d5j3'><dir id='7d5j3'><q id='7d5j3'></q></dir></style></legend>
    1. <small id='7d5j3'></small><noframes id='7d5j3'>

      • <bdo id='7d5j3'></bdo><ul id='7d5j3'></ul>
      1. <i id='7d5j3'><tr id='7d5j3'><dt id='7d5j3'><q id='7d5j3'><span id='7d5j3'><b id='7d5j3'><form id='7d5j3'><ins id='7d5j3'></ins><ul id='7d5j3'></ul><sub id='7d5j3'></sub></form><legend id='7d5j3'></legend><bdo id='7d5j3'><pre id='7d5j3'><center id='7d5j3'></center></pre></bdo></b><th id='7d5j3'></th></span></q></dt></tr></i><div id='7d5j3'><tfoot id='7d5j3'></tfoot><dl id='7d5j3'><fieldset id='7d5j3'></fieldset></dl></div>
        <tfoot id='7d5j3'></tfoot>

        为什么 SUM(null) 在 Oracle 中不为 0?

        Why SUM(null) is not 0 in Oracle?(为什么 SUM(null) 在 Oracle 中不为 0?)
      2. <tfoot id='bA409'></tfoot>

        1. <i id='bA409'><tr id='bA409'><dt id='bA409'><q id='bA409'><span id='bA409'><b id='bA409'><form id='bA409'><ins id='bA409'></ins><ul id='bA409'></ul><sub id='bA409'></sub></form><legend id='bA409'></legend><bdo id='bA409'><pre id='bA409'><center id='bA409'></center></pre></bdo></b><th id='bA409'></th></span></q></dt></tr></i><div id='bA409'><tfoot id='bA409'></tfoot><dl id='bA409'><fieldset id='bA409'></fieldset></dl></div>

            • <small id='bA409'></small><noframes id='bA409'>

                • <bdo id='bA409'></bdo><ul id='bA409'></ul>
                    <tbody id='bA409'></tbody>
                  <legend id='bA409'><style id='bA409'><dir id='bA409'><q id='bA409'></q></dir></style></legend>

                  本文介绍了为什么 SUM(null) 在 Oracle 中不为 0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  遇到空值时,请解释 SUM 函数在 Oracle 中的内部功能,我们将不胜感激:

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

                  select sum(null) from dual;
                  is null
                  

                  但是当一个空值在一个值序列中时(比如一个可为空的列的总和),空值的计算值为0

                  But when a null value is in a sequence of values (like sum of a null-able column), the calculated value of null value will be 0

                  select sum(value) from
                  (
                  select case when mod(level , 2) = 0 then null else level end as value from dual
                  connect by level <= 10
                  )
                  is 25
                  

                  看到

                  select (1 + null) from dual
                  is null
                  

                  因为任何带有 null 的操作都会导致 null(除了 is null 运算符).

                  ==========================
                  由于评论而有所更新:

                  As any operation with null will result null (except is null operator).

                  ==========================
                  Some update due to comments:

                  create table odd_table as select sum(null) as some_name from dual;
                  

                  将导致:

                  create table ODD_TABLE
                  (
                    some_name NUMBER
                  )
                  

                  为什么 some_name 列是 number 类型?

                  Why some_name column is of type number?

                  推荐答案

                  SQL 在计算 SUM 时不会将 NULL 值视为零,它会忽略它们:

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

                  返回表达式中所有值的总和,或仅返回 DISTINCT 值.空值被忽略.

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

                  这仅在一种情况下有所不同 - 当被累加的序列不包含数字项时,只有 NULLs:如果至少存在一个数字,则结果将是数字.

                  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.

                  这篇关于为什么 SUM(null) 在 Oracle 中不为 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  <i id='KE5DG'><tr id='KE5DG'><dt id='KE5DG'><q id='KE5DG'><span id='KE5DG'><b id='KE5DG'><form id='KE5DG'><ins id='KE5DG'></ins><ul id='KE5DG'></ul><sub id='KE5DG'></sub></form><legend id='KE5DG'></legend><bdo id='KE5DG'><pre id='KE5DG'><center id='KE5DG'></center></pre></bdo></b><th id='KE5DG'></th></span></q></dt></tr></i><div id='KE5DG'><tfoot id='KE5DG'></tfoot><dl id='KE5DG'><fieldset id='KE5DG'></fieldset></dl></div>

                        • <bdo id='KE5DG'></bdo><ul id='KE5DG'></ul>
                          <legend id='KE5DG'><style id='KE5DG'><dir id='KE5DG'><q id='KE5DG'></q></dir></style></legend>

                            <tbody id='KE5DG'></tbody>

                          <small id='KE5DG'></small><noframes id='KE5DG'>

                            <tfoot id='KE5DG'></tfoot>