Created
February 27, 2018 10:13
-
-
Save den-kozlov/9e4f2f42713c3544fc67632189f9ad3d to your computer and use it in GitHub Desktop.
use as: SELECT * FROM TABLE(split_string('1,2,3'))
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
TYPE varchar_tab IS TABLE OF VARCHAR2(100); | |
FUNCTION split_string(in_comma_separated_values IN VARCHAR2) RETURN varchar_tab | |
PIPELINED IS | |
val VARCHAR2(32); | |
i_from PLS_INTEGER := 1; | |
i_to PLS_INTEGER; | |
len PLS_INTEGER; | |
BEGIN | |
len := LENGTH(in_comma_separated_values); | |
LOOP | |
i_to := instr(in_comma_separated_values, ',', i_from, 1); | |
IF i_to = 0 | |
THEN | |
i_to := len + 1; | |
END IF; | |
val := substr(in_comma_separated_values, i_from, i_to - i_from); | |
PIPE ROW(val); | |
IF i_to >= len | |
THEN | |
RETURN; | |
END IF; | |
i_from := i_to + 1; | |
END LOOP; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment