CREATE OR REPLACE FUNCTION CONCAT_LIST( CURSELECT SYS_REFCURSOR ,
SEPARATOR IN VARCHAR2 DEFAULT ',')
RETURN VARCHAR2 IS
RET VARCHAR2(32000);
TMP VARCHAR2(4000);
BEGIN
LOOP
FETCH CURSELECT INTO TMP;
EXIT WHEN CURSELECT%NOTFOUND;
RET :=  RET||TMP||SEPARATOR;
END LOOP;
RETURN SUBSTR(RET,1,LENGTH(RET)-LENGTH(SEPARATOR));
END;
/