Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

select's MODEL clause to add columns on the resultset, not just new rows?

Ruslan D.Jul 26 2016 — edited Jul 27 2016

PIVOT can only pivot one value into its one column.

Also PIVOT is not helpful if for examle we want to pivot and (group by) intersecting ranges of values.

So we're planning to use MODEL clause to overcome this limits.

We have to pivot into columns:

- sum(), count() of data over separate quarters for last 2 years and present each quarter's result into its own set of column;

- sum(), count() of data over separate years for last 2 years and present each years's result into its own set of column;

- sum(), count() of data over separate months for last 3  months and present each month's result into its own set of column.

The list of quarters / years / months in the bucketing is fixed and can be hard-coded in the MODEL clause (i.e. it'll be always to look back 2 years).

I have a working prototype doing above using three separate pivots, but it is very inefficient because each pivot has to pass

our huge dataset again.

We expect MODEL might require just one pass over the dataset.

Questions:

- Is it possible for MODEL clause to create new columns (ie. we group by month and product category in a subquery, but MODEL should add columns for the above quarter/year/month buckets)?

- Can't think of a best way to define DIMENSION BY and MEASURES so we could create new columns..

Any ideas are highly appreciated.

Comments

_Dylan_
Like right clicking your query results -> Export Data -> xls...

If that's what you mean, how hard are you really looking?
751486
Thanks for the reply. Right Clicking on Data results -> save as -> excel file allows us to save it as an excel file. But, In TOAD, you can save it as excel instance which actually opens the unsaved excel file with data on it. In short, right click-> save as excel instance -> Excel opens up with the data in it.

-Shiva
_Dylan_
Oh, I think I got what you're looking for now. I don't know of any save as "excel instance", but when you save as an excel file, you can choose to save to the clipboard instead of a file. Then you can switch over to excel and paste into a worksheet.
125857
I've never seen that SQL Developer can do that-it'll just save the data in the specified format and that's it.
1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 24 2016
Added on Jul 26 2016
10 comments
343 views