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

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

猜你喜欢

转载自cainiao1923.iteye.com/blog/2354203