加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle – select count(*)和select count(any_non_null_column)

发布时间:2020-12-12 13:11:29 所属栏目:百科 来源:网络整理
导读:我似乎记得(在Oracle上)从any_table发出select count(*)和从any_table中选择count(any_non_null_column)之间存在差异. 如果有的话,这两个陈述之间有什么区别? COUNT(*)将包括NULLS COUNT(column_or_expression)不会. 这意味着COUNT(any_non_null_column)当
我似乎记得(在Oracle上)从any_table发出select count(*)和从any_table中选择count(any_non_null_column)之间存在差异.

如果有的话,这两个陈述之间有什么区别?

> COUNT(*)将包括NULLS
> COUNT(column_or_expression)不会.

这意味着COUNT(any_non_null_column)当然会给出与COUNT(*)相同的结果,因为没有NULL值会导致差异.

通常,COUNT(*)应该更好,因为可以使用任何索引,因为COUNT(column_or_expression)可能没有索引或SARGable

从ANSI-92(寻找“标量表达式125”)

Case:

a) If COUNT(*) is specified,then the result is the cardinality
of T.

b) Otherwise,let TX be the single-column table that is the
result of applying the <value expression> to each row of T
and eliminating null values. If one or more null values are
eliminated,then a completion condition is raised: warning-
null value eliminated in set function.

同样的规则至少也适用于SQL Server和Sybase

注意:COUNT(1)与COUNT(*)相同,因为1是不可为空的表达式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读