Using Rollup in Oracle

No.of Views1067
Bookmarked0 times
Downloads 
Votes0
By  youngmurukan   On  15 Feb 2010 21:02:15
Tag : Oracle , How to
Using Rollup in Oracle
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article we would see how to get the subtotal and grand total based on specified column in oracle. This would be very helpful in when you create any reports rather than doing in several steps we can do it by a single query.

Explanation

In that query we need to use Rollup function in Group By clause. In Rollup function we need to specify the column names. Based these columns query would return the subtotals.

And rollup would return Grand Total too at last.

Background

You must know at least about oracle and TOAD.

You need nothing but oracle and any editor like TOAD so on. I have used the TOAD editor for this.

Script for this,

Image Loading...

Here I need to get the subtotal of UNRESTRICTED_QTY for each PRODUCT_NO,LOCATION_NO.

According to my query result was as shown below,

Result

Image Loading.....

In these results you can replace by your own word by using Grouping() function with columns which we are specified in Rollup function, in select clause as shown below.

But if you use Grouping() alone, it would return only either 1 or 0.

if that there is value for that record, then it would will return 0.

If there is no value for that record, then it would return 1.

Image Loading...


Result

Image loading...

So Grouping() function alone returning either 0 or 1, you can replace those values by using case clause as shown below,

Image loading...

Result


Image Loading...

Thank you

Murukan

 
Sign Up to vote for this article
 
About Author
 
youngmurukan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 May 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top