Oracle 11g R2- LISTAGG Function

The below is one of the best example for LISTAGG

 DEPTNO ENAME
———- ———-
        20   SRINI
        30   RAJU
        30   WARD
              

Desired Output:

    DEPTNO EMPLOYEES
———- ————————————————–
        20 SRINI
        30 RAJU,WARD

SQL Query:

SELECT deptno, LISTAGG(ename, ‘,’) WITHIN GROUP (ORDER BY ename) AS employees
FROM   emp
GROUP BY deptno;

    DEPTNO EMPLOYEES
———- ————————————————–
        20 SRINI

        30 RAJU,WARD

2 rows selected.

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.