GROUPING Function

Contact Us or call 1-877-932-8228
GROUPING Function

GROUPING Function

The DECODE function provides conditional functionality (like if/else logic in procedural programming languages. It will be covered in depth in the chapter on conditional processing).

Code Sample:

Enhancing-Groups-With-Rollup-and-Cube/Demos/grouping.sql
SELECT 
	decode(grouping(region_name),0,region_name,'GRAND') AS region_name,
	decode(grouping(country_name),0,country_name,'TOTAL') AS country_name,  
	count(*) 
FROM emp_details_view 
GROUP BY ROLLUP(region_name, country_name);

The grouping function returns a zero (indicating a detail record) or a one (indicating a summary row). Oracle calls the summary rows superaggregate rows to distinguish them from regular grouped rows. The GROUPING function can be used with a DECODE statement (which provides if/else like functionality) to display labels identifying a summary row.

Next