Free Oracle Tips

Oracle Consulting Oracle Training Development
 
Oracle Home
Oracle Training
SQL Tuning Consulting
Oracle Tuning Consulting
Data Warehouse Consulting
Oracle Project Management
Oracle Security Assessment
Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Internals Magazine
Oracle Links
Oracle Monitoring
Remote Support Benefits
Remote Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





   

 


        
 
     Oracle:

 
Using the GROUPING function
 
To handle these NULL issues, Oracle 8i introduces a new function called GROUPING.  Using a single column as its argument, Grouping returns 1 when it encounters a NULL value created by a ROLLUP or CUBE operation.
 
That is, if the NULL indicates the row is a subtotal, GROUPING returns a 1. Any other type of value, including a stored NULL, will return a 0.
 
GROUPING = 0 is a stored NULL not created by ROLLUP or CUBE
 
GROUPING = 1 is a NULL value created by ROLLUP or CUBE
 
Here is a simple example at aggregates employee data.
 
 
SELECT
   deptno,
   job,
   count(*),
   sum(sal),
GROUPING(Job)
FROM
   emp
GROUP BY
   ROLLUP(deptno,job);
 
 
 
   DEPTNO JOB         COUNT(*)  SUM(SAL) GROUPING(JOB)
--------- --------- --------- --------- -------------
       10 CLERK              1       1300              0
       10 MANAGER            1       2450              0
       10 PRESIDENT          1       5000              0
       10                    1       1000              0
       10                    4       9750              1
<== Aggregate
       20 ANALYST            2       6000              0
       20 CLERK              2       1900              0
       20 MANAGER            1       2975              0
       20                    5      10875              1
       30 CLERK              1        950              0
       30 MANAGER            1       2850              0
       30 SALESMAN           4       5600              0
       30                    6       9400              1
<== Aggregate
                            15      30025              1
<== Aggregate
 
 
Here we see that the database has computed aggregate values for each department and also for the total result set.


 

     

Remote DBA Service
 

Free Oracle dictionary reference poster

BC Oracle support

Oracle books by Rampant

Oracle monitoring software

North Carolina Oracle Users Group

 

 Arabian horse breeder

Seeing eye horses

 

 

 

 

 

Burleson is the American Team

American Flag

 

 

BC Remote Oracle Support
P.O. Box 511 • Kittrell, NC, 27544

Remote DBA

 

Copyright © 1996 -  2009 by Burleson Enterprises, Inc. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.