Oracle自定义splitstr

 

CREATE OR REPLACE FUNCTION SPLITSTR(P_STRING    IN VARCHAR2,
                                    P_DELIMITER IN VARCHAR2)
  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));
      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;

--调用

SELECT SPLITSTR('a,b,c,d',',') FROM DUAL

 

posted on 2023-04-11 11:42  米卢的教练  阅读(21)  评论(0编辑  收藏  举报

导航