What is the usage of the count function in Oracle?
In Oracle database, the COUNT function is used to calculate the number of rows in a specified column or expression. Its general syntax is:
COUNT(expression)
“Where expression is the column or expression to be counted.”
The COUNT function returns an integer representing the number of rows that meet the specified conditions. If the expression is NULL, it is not included in the row count calculation.
Example:
SELECT COUNT(*) FROM employees;
This will calculate the total number of rows in the employees table.
SELECT COUNT(employee_id) FROM employees;
This will calculate the number of rows in the employees table where the employee_id column is not NULL.
SELECT COUNT(DISTINCT department_id) FROM employees;
This will calculate the number of rows with different department_id values in the employees table.