Sunday, April 10, 2011

Oracle - Converting rows to columns

wm_concat


This function converts all the rows from a table to a single column.


Example:-



SQL> create table temp
  2  (
  3  a integer
  4  );


Table created.


SQL> insert into temp values(1);
1 row created.


SQL> insert into temp values(2);
1 row created.


SQL> insert into temp values(3);
1 row created.


SQL> insert into temp values(4);
1 row created.


SQL> commit;


Commit complete.


SQL> select * from temp;


         A
----------
         1
         2
         3
         4


SQL> select wm_concat(a) from temp;


WM_CONCAT(A)
--------------------------------------------------


1,2,3,4


SQL>

No comments:

Post a Comment