The difference between count (1) and COUNT (*) in Oracle

Source: Internet
Author: User

Count Detailed:   

COUNT (*) returns the total number of rows that exist in the table, including rows with a value of null, whereas count (column name) returns the total number of all rows except null in the table (columns with default values will also be counted).

Distinct the column name, the result will be the result of dropping the value null and repeating the data

Examples are shown below:

sql> Create table test

2 (

3 ename VARCHAR2 (10),

4 sal Number (4)

5);

The table is created.

sql> INSERT INTO test values (' Fxe1 ', 90);

1 rows have been created.

sql> INSERT INTO test (ename) values (' fxe2 ');

1 rows have been created.

sql> INSERT INTO test (ename) values (' fxe3 ');

1 rows have been created.

sql> INSERT INTO test (ename) values (' fxe4 ');

1 rows have been created.

sql> INSERT INTO test values (' fxe5 ', 80);

1 rows have been created.

sql> INSERT INTO test values (' fxe6 ', 80);

1 rows have been created.

Sql> SELECT * from test;

Ename SAL

---------- ----------

FXE1 90

Fxe2

Fxe3

Fxe4

Fxe5 80

Fxe6 80

sql> Select Count (*) from test;

COUNT (*)

----------

6

sql> Select count (sal) from test;

COUNT (SAL)

----------

3

sql> Select count (distinct sal) from test;

COUNT (Distinctsal)

------------------

2

sql> Select distinct sal from test;

SAL

----------

80

90

The difference between count (1) and COUNT (*) in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.