Oracle grant permission for execute

亡梦爱人 提交于 2019-12-24 09:57:56

问题


I've a dynamic sql inside a procedure which creates a view. If I print the string and execute it manually, I'm able to create the view. However in the procedure an exception is thrown as insufficient privileges. I've granted execute,create,all on the procedure to the user, however it still does not work. Any suggestions?


回答1:


Inside packages, privileges granted indirectly (via a role) are dropped. You must grant the necessary privileges on the underlying objects to the account directly; example:

conn sys/sys@DB as sysdba
create user A identified by A;
grant connect, dba to A;
conn A/A@DB
create table test_tab(pk number);

conn sys/sys@DB as sysdba
create user B identified by B;
grant connect, dba to B;
conn B/B@DB
select * from A.test_tab; -- this works

create or replace procedure do_it as
l_cnt pls_integer;
begin
  select count(*) into l_cnt from A.test_tab; -- error on compile
end;

In this example, you need a

grant select on A.test_tab to B;

to make it work (it doesn't matter whether you're using dynamic or static SQL).




回答2:


My guess, based on the little information you've given, is that the procedure is running with definer rights (the default) and the owner of the procedure does not have the privileges required to create the view. It is not clear whether the appropriate solution in your case is to create the procedure with invoker rights instead, or to grant additional privileges to the owner of the procedure.

Posting actual code is always helpful. Does the procedure have definer or invoker rights? Which schema is the view supposed to be created it? What are the actual grant statements that you executed?



来源:https://stackoverflow.com/questions/6521884/oracle-grant-permission-for-execute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!