一种方法是用函数:这里转帖网上摘抄的一个函数
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;
这里提供另外一种方法,tbw利用oracle的正则相关函数实现:
select dbms_lob.substr(regexp_substr('abc,def,ggg,1,2,3,4,5', '[^,]+', 1, x.n)) as player_guid
from dual a, (select rownum n from dual connect by rownum < 100) x
这里利用了函数 regexp_substr和connect by
其中rownum < 100 会连接限制split的次数 '[^,]+'为split拆分的正则表达式,这里为【,】逗号
上面sql语句结果是:
abc
def
ggg
1
2
3
4
5