在对有null值的字段进行count时,发现count(1)与count(字段)得到的记录不一样。
结论:1.count(1)与count(*)得到的结果一致,包含null值。
2.count(字段)不计算null值
3.count(null)结果恒为0
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> desc t_product;
Name Type Nullable Default Comments
------------ ------------ -------- ------- --------
PRODUCT_ID NUMBER(6) Y
PRODUCT_NAME VARCHAR2(50) Y
LIST_PRICE NUMBER(8,2) Y
SQL> SELECT * FROM t_product WHERE list_price IS NULL;
PRODUCT_ID PRODUCT_NAME LIST_PRICE
---------- --------------- ----------
3355 HD 8GB /SI
1770 8MB Cache /NM
SQL> select count(1), count(*), count(list_price),count(null)
2 from t_product
3 where list_price is null;
COUNT(1) COUNT(*) COUNT(LIST_PRICE) COUNT(NULL)
---------- ---------- ----------------- -----------
2 2 0 0