Skip to Main Content

SQL & PL/SQL

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!

Pivot Dynamic Dates to Columns and Value Headers to Rows

Tim DMar 12 2019 — edited Mar 13 2019

I have a table structure similar to this:

Item    Item Descr     StartDate    Inventory    TotSupply   SchedRcpts  ProjOH 
-------------------------------------------------------------------------------
12345   Widget         3/8/2019     50           50          50          100
12345   Widget         3/15/2019    25           25          25          50

I need a query or queries that will result in getting the data in this format/layout (NOTE: dates are dynamic weeks ending Friday):

Item    Item Descr     Value_Type    3/8/2019   3/15/2019 
---------------------------------------------------------
12345   Widget         Inventory     50         25
12345   Widget         TotSupply     50         25
12345   Widget         SchedRcpts    50         25
12345   Widget         ProjOH        100        50

I've tried pivot/unpivot, but it continues to produce errors. I'm okay with running successive queries if needed to pivot the dates and then the values, but my attempts to just pivot or unpivot one of these two values (dates or supply values) produces errors. I'm new to Oracle pivot/unpivot and I'm connecting to an Oracle 11g database.

I've also tried a union for the supply values, but that will produce about 800K rows for just the supply values prior to pivoting the dates to columns and that seems it would be very slow, but I will do that if it's my only choice. I'm using a read-only account, so I cannot create tables.

Any help is appreciated

This post has been answered by BluShadow on Mar 12 2019
Jump to Answer
Comments
Post Details
Added on Mar 12 2019
9 comments
2,530 views