CREATE OR REPLACE FUNCTION col_to_row (p_select IN VARCHAR2,
p_dlmtr IN VARCHAR2 DEFAULT ',' )
RETURN VARCHAR2
/*AUTHID CURRENT_USER --Somente o usuário que criou pode executar*/
AS
TYPE c_refcur IS REF CURSOR;
c_dummy c_refcur;
lc_str VARCHAR2(4000);
lc_colval VARCHAR2(4000);
BEGIN
OPEN c_dummy FOR p_select;
FETCH c_dummy INTO lc_colval;
EXIT WHEN c_dummy%NOTFOUND;
lc_str := lc_str || p_dlmtr || lc_colval;
END LOOP ;
CLOSE c_dummy;
RETURN SUBSTR(lc_str,2);
END;
--Executando
SELECT COL_TO_ROW(‘SELECT COL1 FROM TABELA’) FROM DUAL
0 comentários:
Postar um comentário