How can I combine multiple rows into a comma-delimited list in Oracle?

Answer

createtable countries ( country_name varchar2 (100));insertinto countries values('Albania');insertinto countries values('Andorra');insertinto countries values('Antigua');SELECT SUBSTR (SYS_CONNECT_BY_PATH (country_name ,','),2) csv
      FROM(SELECT country_name , ROW_NUMBER ()OVER(ORDERBY country_name ) rn,
                   COUNT (*)OVER() cnt
              FROM countries)WHERE rn = cnt
STARTWITH rn =1CONNECTBY rn = PRIOR rn +1;

CSV                                                                             
--------------------------
Albania,Andorra,Antigua                                                         

1row selected.

All oracle Questions

Ask your interview questions on oracle

Write Your comment or Questions if you want the answers on oracle from oracle Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---