潇湘沐
这里有一个简单的方法,不需要strgg或创建函数。create table countries ( country_name varchar2 (100));insert into countries values ('Albania');insert into countries values ('Andorra');insert into countries values ('Antigua');SELECT SUBSTR (SYS_CONNECT_BY_PATH (country_name , ','), 2) csv FROM (SELECT country_name , ROW_NUMBER () OVER (ORDER BY country_name ) rn,
COUNT (*) OVER () cnt FROM countries)
WHERE rn = cntSTART WITH rn = 1CONNECT BY rn = PRIOR rn + 1;CSV
--------------------------Albania,Andorra,Antigua
1 row selected.正如其他人所提到的,如果您在11gR2或更高的位置,现在可以使用listagg,这要简单得多。select listagg(country_name,', ') within group(order by country_name) csv from countries;CSV
--------------------------Albania, Andorra, Antigua1 row selected.