您的位置:首页 > 数据库 > Oracle

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

2009-12-08 21:15 357 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  null oracle insert sql table