The GROUPING Function

A problem with the ROLLUP and CUBE options is the difficulty in identifying the rows that are subtotals. One way to identify subtotal rows is to identify the rows that contain null values. Expressions that are subtotaled will have a value in the column that determines the ROLLUP. The other expressions will contain null values. However, if the database contains nulls, this technique will not work because Oracle will also roll up null value records. Oracle developed the GROUPING function to help the identification of ROLLUP records.

GROUPING functions accept only one parameter. The GROUPING function returns a value of 1 if the row is a subtotal row for the target expression. The function will return a value of 0 if the row ...

Get Oracle SQL and PL/SQL Handbook: A Guide for Data Administrators, Developers, and Business Analysts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.