LISTAGG EXAMPLE IN ORACLE

(Last Updated On: August 11, 2016)

LISTAGG EXAMPLE IN ORACLE:

LISTAGG can be used to get all the row values in single row.

Example: [STUDENT_TABLE]

Student_id Student_Name Course_id
1                   Naveen                A100
2                   Hems                  A130
3                   Chudar               A100
4                   Balaji                  A100
5                  Aravind                A120
6                   RVS                    A130
7                    JP                      A130
8                    Arun                   A120
9                  K Aravind             A100

Now you want to get the result with respect to the course_id then the query will be,

SELECT LISTAGG(Student_Name,’,’) WITHIN GROUP (ORDER BY Student_Name) from STUDENT_TABLE group by Course_id;

So Result will come like this,

Naveen,Chudar, Balaji, K Aravind
Hems, RVS, JP
Aravind, Arun

316 total views, 0 views today

Leave a Reply

Your email address will not be published. Required fields are marked *