create type char_table is table of varchar2(4000);--创建自定义类型脚本create or replace function split_string(pi_str in
create type char_table is table of varchar2(4000);--创建自定义类型脚本
create or replace function split_string(pi_str in varchar2, pi_separator in varchar2) --创建函数
return char_table
is
v_char_table char_table;
--create type char_table is table of varchar2(4000);--创建自定义类型脚本
v_temp varchar2(4000);
v_element varchar2(4000);
begin
v_char_table := char_table();
v_temp := pi_str;
while instr(v_temp, pi_separator) > 0
loop
v_element := substr(v_temp,1,instr(v_temp, pi_separator)-1);
v_temp := substr(v_temp, instr(v_temp,pi_separator)+ length(pi_separator) , length(v_temp));
v_char_table.extend;
v_char_table(v_char_table.count) := v_element;
end loop;
v_char_table.extend;
v_char_table(v_char_table.count) := v_temp;
return v_char_table;
end split_string;
--测试
select split_string('safs,utjtje,2412q1a,egwsff',',') from dual;
--实际应用
create or replace function initCFJG
return varchar2
is
pragma AUTONOMOUS_TRANSACTION;
guid varchar2(80):=''; --GUID
zjid varchar2(80):='';--主键id
lxid varchar2(80):=''; --处理结果类型id
lxidsArr char_table; --字符串数组,,char_table为自定义类型
begin
for p in(select lp_id,zfgl_id,case_id,cf_amount from dzjc_xzzf_t_zfgl where lp_id is not null)
loop
zjid:=p.zfgl_id;
select split_string(p.lp_id,',') into lxidsArr from dual;
for i in 1 .. lxidsArr.count
loop
--dbms_output.put_line(lxidsArr(i));
select GETGUID into guid from dual;
select cfjd_cflx into lxid from cf_t_cfjd where rownum =1 and cfjd_id=lxidsArr(i);
if lxid='3'then
insert into dzjc_xzzf_t_zfgl(zfgl_id,case_id,lp_id,cf_amount) values (guid,p.case_id,'159_'||lxid,p.cf_amount);
else
insert into dzjc_xzzf_t_zfgl(zfgl_id,case_id,lp_id) values (guid,p.case_id,'159_'||lxid);
end if;
end loop;
delete from dzjc_xzzf_t_zfgl where zfgl_id=zjid;
end loop;
commit;
return '执行完成';
end;
本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:php中文网