0
我想直接授予,因爲從PLSQL授予是不允許的。這裏是我的存儲過程:如何從存儲過程啓動SQL命令行?
connect pta/[email protected]
create or replace procedure refresh_all_privs_in_role(p_role_code varchar2)
is
v_role role.role_db%type;
type rec_user is table of varchar2(30) index by binary_integer;
v_users rec_user;
counter integer := 0;
type rec_menu_priv is table of menu.menu_role_priv%type index by binary_integer;
v_privs rec_menu_priv;
function get_menu_privs(p_menu_id number)
return rec_menu_priv
is
privs menu.menu_role_priv%type;
ret rec_menu_priv;
counter_priv integer := 0;
begin
select menu_role_priv into privs from menu where menu_id = p_menu_id;
if instr(privs,'|') = 0 then
ret(1) := privs;
else
while instr(privs,'|') > 0 loop
counter_priv := counter_priv + 1;
ret(counter_priv) := substr(privs, 1, instr(privs,'|') - 1);
privs := substr(privs, instr(privs,'|') + 1);
end loop;
counter_priv := counter_priv + 1;
ret(counter_priv) := privs;
end if;
return ret;
end;
begin
select lower(role_db) into v_role from role where role_code = p_role_code;
for i_user in (select grantee from dba_role_privs where lower(granted_role) = v_role) loop
counter := counter + 1;
v_users(counter) := i_user.grantee;
end loop;
execute immediate 'drop role "' || v_role || '"';
execute immediate 'create role "' || v_role || '" not identified';
for menu_ in (select menu_id from role_menu where role_code = p_role_code)
loop
v_privs := get_menu_privs(menu_.menu_id);
for i in v_privs.FIRST..v_privs.LAST loop
execute immediate 'grant ' || v_privs(i) || ' to "' || v_role || '"'; // open sql command-line connected as some username/[email protected] here to execute the grant
end loop;
end loop;
for i in v_users.FIRST..v_users.LAST loop
execute immediate 'grant "' || v_role || '" to ' || v_users(i);
end loop;
end;
/
那麼如何打開SQL命令行來執行對我評論就行了GRANT,並關閉它在該語句完成?
更新:
這裏是程序的用戶擁有者和來電:
connect system/[email protected] as sysdba
create user pta identified by pta
/
grant dba to pta
/
grant create user to pta
/
grant alter user to pta
/
grant create role to pta
/
grant drop any role to pta
/
grant select on dba_role_privs to pta
/
grant select on role_tab_privs to pta
/
grant select on dba_roles to pta
/
通常情況下,不允許從pl sql授予權限。你有什麼例外嗎? –
我在運行時遇到「權限不足」錯誤。 – pheromix
他有dba的角色,它是程序本身的創建者。 – pheromix