splitstr字符串分割--'1,2,3,4,5'

CREATE OR REPLACE TYPE str_split IS TABLE OF VARCHAR2 (4000);--定义数组
CREATE OR REPLACE FUNCTION splitstr(p_string IN VARCHAR2, p_delimiter IN VARCHAR2)

/**
  字符串分割 select COLUMN_VALUE from table(splitstr('a|b|c|d','|'));
  CREATE OR REPLACE TYPE str_split IS TABLE OF VARCHAR2 (4000);--定义数组
  */
    RETURN str_split
    PIPELINED
AS
    v_length   NUMBER := LENGTH(p_string);
    v_start    NUMBER := 1;
    v_index    NUMBER;
BEGIN
    WHILE(v_start <= v_length)
    LOOP
        v_index := INSTR(p_string, p_delimiter, v_start);

        IF v_index = 0
        THEN
            PIPE ROW(SUBSTR(p_string, v_start));--PIPE ROW:管道化表函数
            v_start := v_length + 1;
        ELSE
            PIPE ROW(SUBSTR(p_string, v_start, v_index - v_start));
            v_start := v_index + 1;
        END IF;
    END LOOP;

    RETURN;
END splitstr;
/
 

你可能感兴趣的:(ORACLE)