oracle count()函数对null值的处理

来源:互联网 发布:淘宝贺卡怎么写 编辑:程序博客网 时间:2024/05/19 23:17

count()
括号中如果是列名的话则不包含NULL
如果是*字符或常量 则包括NULL

下面做几个小例子来看一下

SQL> create table test(id number,name varchar2(10));

Table created.

SQL> insert into test values(1,'wh');

1 row created.

SQL> insert into test values(2,'wo');

1 row created.

SQL> insert into test(id) values(2);

1 row created.

SQL> insert into test(name) values('ha');

1 row created.

SQL> insert into test values(null,null);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test;

        ID NAME
---------- ----------
         1 wh
         2 wo
         2
           ha


SQL> select count(1) from test;

  COUNT(1)
----------
         5

SQL> select count(*) from test;

  COUNT(*)
----------
         5

SQL> select count(id) from test;

 COUNT(ID)
----------
         3

SQL> select count(name) from test;

COUNT(NAME)
-----------
          3

原创粉丝点击