oracle user defined split char
CREATE TYPE cuxstrtoarray IS TABLE OF VARCHAR2(2000);
CREATE FUNCTION strtoarray(
str1 VARCHAR2,
strsplit VARCHAR2
)
RETURN cuxstrtoarray IS
l_array cuxstrtoarray;
BEGIN
WITH a AS
(SELECT str1 a
FROM DUAL)
SELECT DECODE(b, 0, SUBSTR(a, c), SUBSTR(a, c, b - c))
BULK COLLECT INTO l_array
FROM (SELECT a,
b,
(LAG(b, 1, 0) OVER(ORDER BY lv)) + 1 c
FROM (SELECT a,
INSTR(a, strsplit, 1, LEVEL) b,
LEVEL lv
FROM a
CONNECT BY LEVEL <= (LENGTH(a) - LENGTH(REPLACE(a, strsplit, ''))) + 1));
RETURN l_array;
END strtoarray;
DECLARE
l_array cuxstrtoarray;
str1 VARCHAR2(2000) := '2010015447,WK7280MD,WX0057';
strsplit VARCHAR2(1) := ',';
BEGIN
l_array := strtoarray(str1, strsplit);
FOR i IN 1 .. l_array.COUNT LOOP
DBMS_OUTPUT.put_line('l_Array(' || i || ')=' || l_array(i));
END LOOP;
END;