一个oracle根据特定字符截取数据
sql split
创建用于存储分开的值容器:create or replace type ty_str_split is table of varchar2 (4000)
创建分离的方法并返回:
create or replace function fn_split(p_str in varchar2,
p_delimiter in varchar2)
return ty_str_split
is
j int := 0;
i int := 1;
len int := 0;
len1 int := 0;
str varchar2(4000);
str_split ty_str_split := ty_str_split();
begin
len := length(p_str);
len1 := length(p_delimiter);
while j < len loop
j := instr(p_str, p_delimiter, i);
if j = 0 then
j := len;
str := substr(p_str, i);
str_split.extend;
str_split(str_split.count) := str;
if i >= len then
exit;
end if;
else
str := substr(p_str, i, j - i);
i := j + len1;
str_split.extend;
str_split(str_split.count) := str;
end if;
end loop;
return str_split;
end fn_split;
得到相关的结果:
for i in 1 .. split_str_1.count loop
tmp_str1 := split_str_1(i);
end loop;