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!

Converting rows into columns

1052085Sep 24 2015 — edited Sep 24 2015

Hi,

I have a table with records similar to below. I want to convert rows into column based on the 2 fields.

Oracle Version 11.2

Source Table:

with tbl_nm as

(

select 'Joby' NM,    'A'     GRP,    'ACFHFJ'  CODE  from dual union

select 'Joby'     ,    'B'        ,    'HFJUNG'        from dual union

select 'Joby'     ,    'C'        ,    'BHJFGH'        from dual union

select 'Paul'     ,    'A'        ,    'JKUMGH'        from dual union

select 'Paul'     ,    'B'        ,    'KJUNHG'        from dual union

select 'Matt'     ,  'B'        ,    'HFUFJF'        from dual union

select 'Matt'      ,    'C'        ,    'HGJGUN'        from dual union

select 'Anna'     ,    'A'        ,    'JDHDUG'        from dual union

select 'Anna'     ,    'C'        ,    'JGUGNH'        from dual

)

select * from tbl_nm

Output I need:

with tbl_nm as

(

select 'Joby' NM,    'ACFHFJ'   A,    'HFJUNG'  B,  'BHJFGH'    C from dual union

select 'Paul'    ,    'JKUMGH'    ,    'KJUNHG'   ,   NULL       from dual union

select 'Matt'     ,     NULL        ,    'HFUFJF'   ,  'HGJGUN'      from dual union

select 'Anna'    ,    'JDHDUG'    ,     NULL      ,  'JGUGNH'      from dual

)

select * from tbl_nm

Can someone please help on this?

Thanks,

Gangadhar

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2015
Added on Sep 24 2015
4 comments
796 views