oracle存储过程传入一个字符串参数'1,2,3,4,5,6,7,8',如何分割并转为数字?
1个回答
展开全部
create or replace type type_split as table of varchar2(50); --创建一个 type ,如果为了使split函数具有通用性,请将其size 设大些。
--创建function
create or replace function split
(
p_list varchar2,
p_sep varchar2 := ','
) return type_split pipelined
is
l_idx pls_integer;
v_list varchar2(50) := p_list;
begin
loop
l_idx := instr(v_list,p_sep);
if l_idx > 0 then
pipe row(substr(v_list,1,l_idx-1));
v_list := substr(v_list,l_idx+length(p_sep));
else
pipe row(v_list);
exit;
end if;
end loop;
return;
end split;
使用:
select * from table(split('1,2,3,4,5,6,7,8'
,','));
然后就可以通过“,”来分割数字了
--创建function
create or replace function split
(
p_list varchar2,
p_sep varchar2 := ','
) return type_split pipelined
is
l_idx pls_integer;
v_list varchar2(50) := p_list;
begin
loop
l_idx := instr(v_list,p_sep);
if l_idx > 0 then
pipe row(substr(v_list,1,l_idx-1));
v_list := substr(v_list,l_idx+length(p_sep));
else
pipe row(v_list);
exit;
end if;
end loop;
return;
end split;
使用:
select * from table(split('1,2,3,4,5,6,7,8'
,','));
然后就可以通过“,”来分割数字了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询