ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle count()函数对null值的处理

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

原创 Linux操作系统 作者:弦音有你 时间:2012-08-08 12:05:23 0 删除 编辑

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26451903/viewspace-740343/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 共享锁和排它锁
请登录后发表评论 登录
全部评论

注册时间:2012-05-16

  • 博文量
    39
  • 访问量
    538103