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!

How to dynamically transpose data into with changing column headers with or without pivot/pivot xml?

VinipandaNov 17 2020 — edited Nov 17 2020

I have 2 scenarios for dynamic pivoting.
Scenario 1:
In the first case,I i need to pivot the data where data source is same table. However the pivot needs to be dynamic as the columns header would keep changing as per column app_id. So if app_id=1. The column header would be A,B,C,D, If app_id=2, column would be CDEF and so on. Also each set of value has an id. So for id, 120 and app_id=1 , column A,B,C,D, would display the values and so on.
The current sample data has only 2 app_ids, but there could be many more, so app_id and labels would kepe changing thus i need to write a dynamic query.
Table is DATA_1
image.pngAnd expected output would be something like this.
P.S. Data is dummy and app_ids, and ids would keep getting inserted and removed with changing column headers,so a dynamic solution is needed.
image.png
Scenario 2:
Here were had the data in one table. Now we have separate table containing the labels and current table with values.
SO in table from scenario one we will focus on id, app_id and value columns only.
Select app_id,id,value from data_1;
The labels will come from another table DATA_Labels in column Header_Name:
image.pngSo, for labels we would use header_names. ANd Data_1 and Data_Labels could be joined on basis of app_id.
In case the values exceed column headers, we can assume that the headers would reach say maximum 20. And in case the header/name is not available, it could put some default header name like COL11,COL12 if the value stretches upto there.
I did lot of research but most solutions are too complex and confusing. Any leads would be appreciated.
The solution could be with/without pivot or we can also use collections/arrays if possible. ANything that helps in changing the headers dynamically.

Comments

gimbal2
Answer
SudeepShakya wrote:
i have download jstl-api-1.2.jar and jstl-impl-1.2.jar instead of jstl.jar and standard.jar but they didn't work.
Then you did something wrong. Not much more to say about it when you provide absolutely nothing other than saying "it doesn't work".
Marked as Answer by SudeepShakya · Sep 27 2020
SudeepShakya
the problem is solved. But i don't know what was the cause, i just reinstalled tomcat and pasted the jar files and worked well.
Thanks for reply
gimbal2
Most likely: putting jars where they shouldn't have been.
EJP
Or rather not putting them where they should have been.
gimbal2
EJP wrote:
Or rather not putting them where they should have been.
Nah, not in this case I think. I believe the OP when he says he installed Tomcat fresh and copy/pasted the same stuff into it. So my assumption is that the old installation was broken due to jar pollution.
SudeepShakya
Well guys stop arguing. None of u are right.
gimbal2
SudeepShakya wrote:
Well guys stop arguing. None of u are right.
Then prove it. Tell what is wrong so other people with the same issue may benefit.
1 - 7

Post Details

Added on Nov 17 2020
3 comments
3,091 views