SQL COUNT() Function
SQL COUNT() function return the number of rows in a SELECT statement.
Supported Oracle SQL Version
- Oracle 8i
- Oracle 9i
- Oracle 10g
- Oracle 11g
- Oracle 12c
- Oracle 18c
Syntax
COUNT( * )
COUNT( [ DISTINCT | ALL ], expression )
Example
Consider following emp_salary is our example table to count total number of rows, count distinct value of column. Using SQL COUNT function.
SQL> SELECT * from emp_salary;
NUM NAME SALARY
---------- ------------------------- ----------
2 Max Miller 2830
3 Beccaa Moss 2175
4 Paul Singh 5405
5 Ken Myer 3390
6 Jack Evans 3870
6 Jack Evans 3870
5 Ken Myer 3390
7 rows selected.
SQL> SELECT COUNT(*) FROM emp_salary;
COUNT(*)
----------
7
SQL> SELECT COUNT(name) FROM emp_salary;
COUNT(NAME)
-----------
7
SQL> SELECT COUNT(DISTINCT name) FROM emp_salary;
COUNT(DISTINCTNAME)
-------------------
5