This Oracle tutorial explains how to use the Oracle/PLSQL GROUP_ID function with syntax and examples.
The Oracle/PLSQL GROUP_ID function assigns a number to each group resulting from a GROUP BY clause. The GROUP_ID function is most commonly used to identify duplicated groups in your query results.
For each unique group, the GROUP_ID function will return 0. When a duplicated group is found, the GROUP_ID function will return a value >0.
The syntax for the GROUP_ID function in Oracle/PLSQL is:
There are no parameters or arguments for the GROUP_ID function.
The GROUP_ID function returns a numeric value.
The GROUP_ID function can be used in the following versions of Oracle/PLSQL:
Let's look at some Oracle GROUP_ID function examples and explore how to use the GROUP_ID function in Oracle/PLSQL.
For example:
You could use the HAVING clause to eliminated duplicated groups as follows: