儲存過程的 建立 和 呼叫

2021-06-29 04:24:52 字數 4837 閱讀 3967

1、建立儲存過程has_permission:

create or replace procedure has_permission(contentid in varchar2,contenttype in number,privilege in number,userid in number,returncode out number)

ismaxprivilege number default -1; --最大許可權級別

dirid varchar2(50);--檔案的目錄id

stdtype number;--標準圖/標準工具/標準模組 型別

begin

--查詢使用者最大的許可權資料--

--如果是 預審庫檔案

if contenttype =1 then

select max(f.dir_id) into dirid from sj_pre_file f where f.id = contentid;

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and (

(d.content_type= 2 and d.content_id in (select j.id from sj_pre_category j start with j.id = dirid connect by prior j.parent_id = j.id))

or(d.content_type= contenttype and d.content_id = contentid)

);end if;

--如果是 預審庫目錄

if contenttype =2 then

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and d.content_type= contenttype

and d.content_id in (select j.id from sj_pre_category j start with j.id = contentid connect by prior j.parent_id = j.id);

end if;

--如果是 成果庫檔案

if contenttype =3 then

select max(f.dir_id) into dirid from sj_lib_file f where f.id = contentid;

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and (

(d.content_type = 4 and d.content_id in (select j.id from sj_lib_category j start with j.id = dirid connect by prior j.parent_id = j.id))

or(d.content_type = contenttype and d.content_id = contentid )

);end if;

--如果是 成果庫目錄

if contenttype =4 then

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and d.content_type= contenttype

and d.content_id in (select j.id from sj_lib_category j start with j.id = contentid connect by prior j.parent_id = j.id);

end if;

--如果是 標準庫目錄

if contenttype =6 then

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and d.content_type= contenttype

and d.content_id in (select j.id from sj_std_type j start with j.id = contentid connect by prior j.parent_id = j.id);

end if;

--如果是 標準圖

if contenttype =7 then

select max(chart.type) into stdtype from sj_std_chart chart where chart.id = contentid;

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and(

(d.content_type= 6 and d.content_id in (select j.id from sj_std_type j start with j.id = stdtype connect by prior j.parent_id = j.id))

or(d.content_type= contenttype and d.content_id = contentid)

);end if;

--如果是 標準工具

if contenttype =8 then

select max(tools.type) into stdtype from sj_std_tools tools where tools.id = contentid;

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and(

(d.content_type= 6 and d.content_id in (select j.id from sj_std_type j start with j.id = stdtype connect by prior j.parent_id = j.id))

or(d.content_type= contenttype and d.content_id = contentid)

);end if;

--如果是 標準模組

if contenttype =9 then

select max(module.type) into stdtype from sj_std_module module where module.id = contentid;

select max(d.privilege) into maxprivilege from sj_dac d,sys_user_role ur

where d.owner_id = ur.role_id

and d.owner_type = 3

and ur.user_id = userid

and(

(d.content_type= 6 and d.content_id in (select j.id from sj_std_type j start with j.id = stdtype connect by prior j.parent_id = j.id))

or(d.content_type= contenttype and d.content_id = contentid)

);end if;

--判斷使用者是否存在指定的許可權(1:存在,0:不存在)

if maxprivilege >= privilege then

returncode := 1;

end if;

if maxprivilege < privilege then

returncode := 0;

end if;

end has_permission;

2、呼叫儲存過程:

declare

returncode number;

begin

-- call the procedure

has_permission('6567',2,1,19791,returncode);

dbms_output.put_line('returncode=' || returncode);

end;

MySQL儲存過程的建立和呼叫

mysql儲存過程弱爆了。下面這個建立 任何地方不匹配都報錯,包括空格!delimiter begin 許可權檢查 by wuzude 2018 01 22 ver 1.0 declare rawsum int 1 default 0 行計數器 declare projid int 4 defaul...

MySQL儲存過程的建立和呼叫

建立 delimiter create procedure authenti in p1 varchar 32 in p2 varchar 32 in p3 varchar 32 in p4 varchar 45 out p5 int begin 許可權檢查 by wuzude 2018 01 22...

MYSQL儲存過程的建立和呼叫

建立儲存過程 建立過程呼叫 create procedure sp name proc parameter characteristics routine bodycreate procedure 為用來建立儲存函式的關鍵字 sp name為儲存過程的名稱 proc parameter為指定儲存過程...