Concatenate string : LISTAGG Analytic Function in 11g Release 2
The LISTAGG analytic function was introduced in Oracle 11g Release 2, default aggregate strings.
Example 1:
SELECT LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
FROM emp;
EMPLOYEES
---------- --------------------------------------------------
CLARK,KING,MILLER,ADAMS,FORD,JONES,SCOTT,SMITH,ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
Example 2:
Select LISTAGG(gm.attribute2, ',') WITHIN GROUP (ORDER BY gm.attribute2)
from gme.gme_material_details gm
Example 3:
SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
FROM emp
GROUP BY deptno;
DEPTNO EMPLOYEES
---------- --------------------------------------------------
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
The LISTAGG analytic function was introduced in Oracle 11g Release 2, default aggregate strings.
Example 1:
SELECT LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
FROM emp;
EMPLOYEES
---------- --------------------------------------------------
CLARK,KING,MILLER,ADAMS,FORD,JONES,SCOTT,SMITH,ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
Example 2:
Select LISTAGG(gm.attribute2, ',') WITHIN GROUP (ORDER BY gm.attribute2)
from gme.gme_material_details gm
Example 3:
SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
FROM emp
GROUP BY deptno;
DEPTNO EMPLOYEES
---------- --------------------------------------------------
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD