Skip to content
Advertisement

Oracle select column names dynamically from another table

I have two tables. Lets say tab1 and tab2.

tab1 has data like this:

ID Field Name
00001 col1
00001 col63
00002 col3
00002 col47
00003 col22
00003 col40

Each ID has always 2 Field Name values.

And tab2 has columns col1,col2,col3,col4….col70

I want to select columns dynamically from tab2.

Like for 00001 it should be:

Similarly for 00002 it should be :

Is there any way to achieve this without using function or procedure ? I am using Oracle 11G.

Advertisement

Answer

Assuming that the columns have compatible types, then you can do what you want by using case expressions:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement