当前位置:Gxlcms > mysql > Oracle字符串分割的处理

Oracle字符串分割的处理

时间:2021-07-01 10:21:17 帮助过:21人阅读

1.首先要先创建数组 create or replace type t_ret_table is table of varchar2(20); 2.利用自定义函数实现一,利用函数返回数组

1.首先要先创建数组

create or replace type t_ret_table is table of varchar2(20);

2.利用自定义函数实现一,利用函数返回数组.
create or replace function f_split_string(var_str in string,var_split In String) return t_ret_table
is
var_out t_ret_table;
var_tmp varchar2(4000);
var_element varchar2(4000);
begin
var_tmp := var_str;
var_out := t_ret_table();
--如果存在匹配的分割符
while instr(var_tmp,var_split)>0 loop
var_element := substr(var_tmp,1,instr(var_tmp,var_split)-1);
var_tmp := substr(var_tmp,instr(var_tmp,var_split)+length(var_split),length(var_tmp));
var_out.extend(1);
var_out(var_out.count) := var_element;
end loop;
var_out.extend(1);
var_out(var_out.count) := var_tmp;
return var_out;
end f_split_string;


3.利用 pipelined Function 函数实现.
create or replace function f_split(var_str in string,var_split In String) return t_ret_table PIPELINED
as
var_tmp varchar2(4000);
var_element varchar2(4000);
n_length Number := length(var_split);
begin
var_tmp := var_str;
while instr(var_tmp,var_split)>0 loop
var_element := substr(var_tmp,1,instr(var_tmp,var_split)-1);
var_tmp := substr(var_tmp,instr(var_tmp,var_split)+n_length,length(var_tmp));
pipe row(var_element);
end loop;
pipe row(var_tmp);
return;
end f_split;

linux

人气教程排行