Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert LISTAGG to XMLAGG Oracle

user10819722May 23 2018 — edited May 23 2018

I have a below SQL and I am trying to convert the LISTAGG to XMLAGG.  My DB version is 12.1 and hence LISTAGG is not supporting more than 4K characters.

Original Query :--

   SELECT LISTAGG (se1.EMAIL, ', ')

    WITHIN GROUP (ORDER BY se1.EMAIL)

    AS listofsgs

    FROM abc se1, xyz team , mno sne

                    WHERE     team.employee_id = se1.employee_id

                          AND sne.non_employee_id = team.non_employee_id

Transformed Query :--

     SELECT XMLAGG(XMLELEMENT(se1.EMAIL||',')).EXTRACT('//text()') 

    WITHIN GROUP (ORDER BY se1.EMAIL)

    AS listofsgs

    FROM abc se1, xyz team , mno sne

       WHERE     team.employee_id = se1.employee_id

   AND sne.non_employee_id = team.non_employee_id

But whenever I run it it keeps failing with Syntax error of missing comma . Is my transformed query correct or am I doing it wrong .

Regards,

This post has been answered by Gaz in Oz on May 23 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 20 2018
Added on May 23 2018
8 comments
8,316 views