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.