Saturday, April 17, 2010

concatenating multiple rows into a single string

--String Aggregation
--source : http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

1* select wm_concat(ename) employees from emp
SQL> /

EMPLOYEES
----------------------------------------------------------------------------------------------------
SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER


SQL> select collect(ename) from emp;

COLLECT(ENAME)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SYSTPhHx4WvmCf/fgQAB/AQFNoQ==('SMITH', 'ALLEN', 'WARD', 'JONES', 'MARTIN', 'BLAKE', 'CLARK', 'SCOTT', 'KING', 'TURNER', 'ADAMS', 'JAMES', 'FORD', 'MILLER')

No comments:

Post a Comment

Followers

About Me

Torrance, CA, United States