Created
December 14, 2010 16:50
-
-
Save joesavak/740683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION getDelimRow(p_slct character varying, p_dlmtr character varying DEFAULT ','::character varying) | |
RETURNS character varying AS | |
$BODY$ | |
DECLARE | |
cur1 refcursor; | |
lc_str VARCHAR(4000); | |
lc_colval VARCHAR(4000); | |
intervalNum INTEGER; | |
BEGIN | |
intervalNum := 0; | |
OPEN cur1 FOR execute(p_slct); | |
LOOP | |
FETCH cur1 INTO lc_colval; | |
if not found then | |
exit; | |
end if; | |
IF intervalNum = 0 THEN | |
lc_str:= lc_colval; | |
intervalNum := 1; | |
ELSE | |
lc_str := lc_str || p_dlmtr || lc_colval; | |
END IF; | |
END LOOP; | |
CLOSE cur1; | |
RETURN lc_str; | |
END; | |
$BODY$ | |
LANGUAGE plpgsql VOLATILE | |
COST 100; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment