美文网首页
oracle根据某个字符拆分字符串

oracle根据某个字符拆分字符串

作者: 没见过的颜色 | 来源:发表于2019-12-30 16:54 被阅读0次

    /*
    *根据某个字符拆分字符串
    */
    CREATE OR REPLACE TYPE str_split IS TABLE OF VARCHAR2 (4000);
    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 * from table(splitstr('Hello,Cnblogs!',','));

    相关文章

      网友评论

          本文标题:oracle根据某个字符拆分字符串

          本文链接:https://www.haomeiwen.com/subject/ubpmoctx.html