Grant statement working in anonymous block but not in procedure
978225Mar 5 2013 — edited Mar 6 2013Hello,
I have the following block which I am running as user SYSTEM from within SQLPlus:
declare
cursor ct is select * from SYS.all_objects where OBJECT_TYPE='TABLE' and OBJECT_NAME not like 'U_%' and OBJECT_NAME not like 'I_%' and OWNER='DN_DWH_STAGE';
begin
for c in ct loop
execute immediate 'GRANT ' || 'SELECT' || ' ON ' || 'DN_DWH_STAGE' || '.' || c.object_name || ' TO ' || 'DN_DWH_CATALOG' || ' WITH GRANT OPTION';
end loop;
end;
/
This works and does what I want it to do - it assigns a bunch of object permissions.
Now I put this code inside a procedure and execute the procedure (copy and paste of all code except for the first line with the procedure declaration):
SQL>
create or replace procedure DN_DWH.fix_user_table_privileges (grantee IN varchar2, onr IN varchar2, priv IN varchar2) IS
cursor ct is select * from SYS.all_objects where OBJECT_TYPE='TABLE' and OBJECT_NAME not like 'U_%' and OBJECT_NAME not like 'I_%' and OWNER='DN_DWH_STAGE';
begin
for c in ct loop
execute immediate 'GRANT ' || 'SELECT' || ' ON ' || 'DN_DWH_STAGE' || '.' || c.object_name || ' TO ' || 'DN_DWH_CATALOG' || ' WITH GRANT OPTION';
end loop;
end;
/
SQL> execute DN_DWH.fix_user_table_privileges('DN_DWH_CATALOG', 'DN_DWH_STAGE', 'SELECT');
This executes without errors, but does not really do anything - the user does not have the permissions I thought this should assign.
If I run the select statement that populates the ct cursor, all the tables I expect to find are in fact returned.
Why does this not work?
To make things even more confusing, an almost identical procedure that assigns "EXECUTE" permissions for functions to the same user (so basically the exact same code just changing the "OBJECT_TYPE" from TABLE to FUNCTION in the ct query) does work like I expect it to.
What am I missing?
Thank you in advance!