The difference between COUNT(1) and COUNT(*) in Oracle is: COUNT(1) ignores null values and only counts non-empty rows; COUNT(*) counts all rows, including null values; which function to choose Depends on: presence of null values, priority for performance or consistency.
The difference between COUNT(1) and COUNT(*) in Oracle
In Oracle, COUNT(1 ) and COUNT(*) are both aggregate functions used to count the number of records in a table, but there are subtle differences between them.
COUNT(1)
COUNT(*)
Which one to choose?
Choose COUNT(1) or COUNT(*) depends on the following factors:
Example
Suppose there is a table named students
that contains the following data:
<code>| id | name | age | |---|---|---| | 1 | John | 20 | | 2 | NULL | 25 | | 3 | Mary | 22 |</code>
If Query this table using COUNT(1), which will return the following results:
<code>SELECT COUNT(1) FROM students; 2</code>
This is because COUNT(1) ignores NULL values.
If you query this table using COUNT(*), it will return the following results:
<code>SELECT COUNT(*) FROM students; 3</code>
This is because COUNT(*) contains NULL values.
The above is the detailed content of The difference between count1 and count* in oracle. For more information, please follow other related articles on the PHP Chinese website!