The following SQL code will convert the multiple rows to a single column using XMLAGG function. The output is same as LISTAGG function.
- SELECT rtrim(XMLAGG(XMLELEMENT(Department,DEPARTMENT_NAME||',' ).EXTRACT('//text()')),',') DEPT_NAME FROM DEPARTMENTS;
- output
- -------
- DEPARTMENT_NAME
- -----------------------
- Administration,Marketing,Purchasing,Human Resources,Shipping,IT,Public Relations,Sales,Executive,Finance,Accounting,Treasury,Corporate Tax,Control And Credit,Shareholder Services,Benefits,Manufacturing,Construction,Contracting,Operations,IT Support,NOC,IT Helpdesk,Government Sales,Retail Sales,Recruiting,Payroll
No comments:
Post a Comment