The Oracle PL/SQL GROUPING function is used to identify the final aggregated rows in grouped rows using ROLLUP and CUBE extension clauses. It returns numeric values to identify the column value in an aggregated row. If it is NOT NULL, it returns zero, otherwise for NULL values of the column, it returns 1.
With the GROUPING function you can distinguish a NULL representing the set of all values in a superaggregate row from a NULL in a regular row.
Note that the expression in the GROUPING function must match one of the expressions in the GROUP_BY clause.
SELECT DECODE(GROUPING(DEPTNO), 1, 'All Departments', DEPTNO) AS DEPT, SUM(SALARY)