如何在Oracle中将多行合并为逗号分隔的列表?
select * from countries
country_name------------Albania Andorra Antigua.....
Albania, Andorra, Antigua, ...
更新
CREATE OR REPLACE FUNCTION APPEND_FIELD (sqlstr in varchar2, sep in varchar2 ) return varchar2 isret varchar2(4000) := '';TYPE cur_typ IS REF CURSOR;rec cur_typ;field varchar2(4000);begin OPEN rec FOR sqlstr; LOOP FETCH rec INTO field; EXIT WHEN rec%NOTFOUND; ret := ret || field || sep; END LOOP; if length(ret) = 0 then RETURN ''; else RETURN substr(ret,1,length(ret)-length(sep)); end if;end;
潇湘沐
侃侃尔雅
慕村225694
相关分类