Code Snippet

Just another Code Snippet site

[Oracle] Row to Column conversion

select 
   deptno,
   rtrim (xmlagg (xmlelement (e, ename || ',')).extract ('//text()'), ',') enames
from 
   emp
group by 
   deptno

,


One thought on “[Oracle] Row to Column conversion

  • Olivier says:

    To sort the elements :

    SELECT
    rtrim (xmlagg (xmlelement (e, ename || ',') ORDER BY ENAME DESC ).extract ('//text()'), ',') AS ORDERED_ENAMES
    FROM ...
    

Leave a Reply

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