procedure hand_mid_sys_bpm_use_role(iorgtype in bpm_compsite_user.orgtype%type,
idate in date) is
v_orgtype bpm_compsite_user.orgtype%type := iorgtype;
v_idate date := idate;
/**異常記錄引數初始化**/
v_proce_name varchar2(100) := 'hand_mid_sys_bpm_use_role';
v_proce_blo_name varchar2(100) := 'hand_mid_sys_bpm_use_role_block';
v_proce_error clob;
--type1
type black_role is record(
v_userattrid1 bpm_compsite_user.userattrid%type);
type t_black_role is table of black_role;
v_black_role t_black_role;
/**定義游標**/
cursor cur_black_role is
select distinct r.userattrid
from bpm_compsite_user r
where r.orgtype = v_orgtype
and r.findtype = 3
and r.userattrid is not null;
/**存放游標中的變數***/
l_userattrid bpm_compsite_user.userattrid%type;
l_orgtype varchar2(10) := case when v_orgtype = 1 then 'bo' when v_orgtype = 2 then 'bq' when v_orgtype = 3 then 'bg' when v_orgtype = 4 then 'bf' when v_orgtype = 5 then 'ba' when v_orgtype = 6 then 'bm' else '' end;
/**變數主要進行切割帶有逗號的userattrid1**/
v_str_start number;
v_str_len number;
v_str_end number;
v_str_count number;
v_str_partcontent varchar2(2000);
/**進行資料判斷,看是否有資料存在***/
v_isfind_rolename number;
v_isfind_data number;
begin
/************************business logic start************************************/
open cur_black_role;
fetch cur_black_role bulk collect
into v_black_role;
for i in 1 .. v_black_role.count loop
--獲取游標中的資料
l_userattrid := v_black_role(i).v_userattrid1;
v_str_count := 0;
loop
v_str_start := v_str_count + 1; --獲取擷取字串起始索引
v_str_count := instr(l_userattrid, ',', v_str_count + 1, 1);
v_str_end := v_str_count - 1; --獲取擷取字串終止索引
--獲取擷取字串長度 if str_count<>0--判斷,如果str_count不等於0
if v_str_count <> 0 then
v_str_len := v_str_end - v_str_start + 1; --獲取擷取字串長度
else
v_str_len := length(l_userattrid); --獲取全部長度
end if;
select substr(l_userattrid, v_str_start, v_str_len)
into v_str_partcontent
from dual;
select count(*)
into v_isfind_data
from mid_sys_bpm_use_role
where userattrid = v_str_partcontent
and orgtype = l_orgtype;
select count(*)
into v_isfind_rolename
from sys_role
where roleid = v_str_partcontent
and roletype = 2
and enabled = 1;
if v_isfind_data = 0 and v_isfind_rolename > 0 then
insert into mid_sys_bpm_use_role
(userattrid,
userattrname,
orgtype,
areaid,
categoryid,
createtime)
values
(v_str_partcontent,
(select rolename
from sys_role t
where roleid = v_str_partcontent),
l_orgtype,
(select areaid from sys_role where roleid = v_str_partcontent),
(select categoryid
from sys_role
where roleid = v_str_partcontent),
v_idate);
end if;
commit;
exit when v_str_count = 0; --當在所剩字串中未找到','時退出
end loop;
end loop;
close cur_black_role;
/************************business logic end*************************************/
exception
when others then
rollback;
v_proce_error := 'format_error_backtrace:' ||
dbms_utility.format_error_backtrace || ';sqlerrm:' ||
sqlerrm || ';sqlcode:' || sqlcode;
insert into sys_pro_error_log
(id,
proce_name,
proce_type,
proce_blo_name,
proce_error,
add_by,
status,
createtime)
values
(uniqueidutil_id.nextval,
v_proce_name,
'p',
v_proce_blo_name,
v_proce_error,
'admin',
'0',
v_idate);
commit;
end hand_mid_sys_bpm_use_role;
Oracle 拆分字串
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...
oracle拆分字串
create or replace type array string is table of varchar2 2000 create or replace function f split string 拆分字串 author zhaohuihua i src in varchar2,待拆分的字...
Oracle拆分字串函式
原文中 有個錯誤 v start v length 1 雖然設定下次查詢起點為字串長度 1,但下次v index還是0,程式不會退回。程式沒有退出條件,故本句應改出使程式退出。exit 還有,原文中未檢測傳入的字串引數為null或為空的情況 此時返回的v index為空 下面改正了,見紅色字型部分。...