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 Using DECODE

916986Feb 16 2012 — edited Feb 17 2012
Hi All,

I am facing some problems while converting the rows into columns. I am using Oracle 10g....

My table structure is given below:-

SQL> select * from t;

ID VALUE
---------- -----------
1 X
1 Y
1 Z
2 A
2 B
2 C

6 rows selected.

My desired output is:-

ID Value
1 X,Y,Z
2 A,B,C


I have tried to achieve this using the below query and I am able to get it..

select id,rtrim (xmlagg (xmlelement (e, value || ',')).extract ('//text()'), ',') from t5 group by id;


What are the different ways to achieve this. Can the same thing be achieved using DECODE.

Please let me know what are the other ways to do it.

Thanks & Regards,
Arijit
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2012
Added on Feb 16 2012
8 comments
13,907 views