The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.
Thanks for the question, Ranjan.
Asked: November 07, 2019 - 5:52 am UTC
Last updated: November 07, 2019 - 8:51 am UTC
Version: 11.2
Viewed 10K+ times! This question is
create table test ( sr varchar2(1),col1 number,col2 number,col3 number ) ; insert into test values ('a',1,2,3); insert into test values ('b',4,5,6); insert into test values ('c',7,8,9);
Col A B C Col1 1 4 7 Col2. 2 5 8 Col2 3 6 9
select * from test unpivot ( val for col in ( col1, col2, col3 ) ); SR COL VAL a COL1 1 a COL2 2 a COL3 3 b COL1 4 b COL2 5 b COL3 6 c COL1 7 c COL2 8 c COL3 9
select * from test unpivot ( val for col in ( col1, col2, col3 ) ) pivot ( min ( val ) for sr in ( 'a' A, 'b' B, 'c' C ) ); COL A B C COL1 1 4 7 COL2 2 5 8 COL3 3 6 9
The Oracle documentation contains a complete SQL reference.