Skip to Main Content
  • Questions
  • granting rights on objects in others schema

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Ambarish.

Asked: June 15, 2000 - 11:13 am UTC

Last updated: September 27, 2010 - 10:12 am UTC

Version: 7.3 onwards

Viewed 10K+ times! This question is

You Asked

Is it possible for the DBA to grant priviliges on objects exisiting in
another user's schema ?

I log in as system/manager and do this:

grant select on scott.dept to cluser;

I get an error message saying insufficient privileges.

Thanks in advance for any help


and Tom said...

In order for this to work directly, using a simple "grant select on scott.dept to cluser", SCOTT would have needed to have granted:

SQL> grant select on dept to SYSTEM with grant option;

Now, a DBA has lots of powerful privileges - among them are:

o create any procedure
o execute any procedure

since by default a procedure executes as the "owner", we can use that to our advantage if we are in a pinch and really need to grant on someone elses objects. (no, this is not a bug, not a hole -- this is a direct side effect of having the incredibably POWERFUL privileges listed above).

If a user has "CREATE ANY PROCEDURE" and "EXECUTE ANY PROCEDURE" (eg:a DBA), the following script works well:

---------------------------------------------------------------
rem 1 = OWNER OF OBJECT
rem 2 = OBJECT NAME
rem 3 = PRIV to grant
rem 4 = WHO to grant to


show user

create procedure &1..dba_parse_$$( p_cur in number, p_str in varchar2 )
as
begin
dbms_sql.parse( p_cur, p_str, dbms_sql.native );
end;
/

column grantee format a8
column grantor format a8

select grantee, grantor, privilege from dba_tab_privs
where owner = upper('&1') and table_name = upper('&2')
/

declare
exec_cursor integer default dbms_sql.open_cursor;
rows_processed number default 0;
sql_stmt varchar2(255);
begin
sql_stmt := 'grant &3 on &1..&2 to &4';
&1..dba_parse_$$( exec_cursor, sql_stmt );
rows_processed := dbms_sql.execute(exec_cursor);
dbms_sql.close_cursor( exec_cursor );
end;
/

select grantee, grantor, privilege from dba_tab_privs
where owner = upper('&1') and table_name = upper('&2')
/

drop procedure &1..dba_parse_$$;
-------------------------------------------------------------



You would run it as such:


SQL> @dogrant scott emp all public

user is "TKYTE"
old 1: create procedure &1..dba_parse_$$( p_cur in number, p_str in varchar2 )
new 1: create procedure scott.dba_parse_$$( p_cur in number, p_str in varchar2
)

Procedure created.

old 2: where owner = upper('&1') and table_name = upper('&2')
new 2: where owner = upper('scott') and table_name = upper('emp')

no rows selected

old 6: sql_stmt := 'grant &3 on &1..&2 to &4';
new 6: sql_stmt := 'grant all on scott.emp to public';
old 7: &1..dba_parse_$$( exec_cursor, sql_stmt );
new 7: scott.dba_parse_$$( exec_cursor, sql_stmt );

PL/SQL procedure successfully completed.

old 2: where owner = upper('&1') and table_name = upper('&2')
new 2: where owner = upper('scott') and table_name = upper('emp')

GRANTEE GRANTOR PRIVILEGE
-------- -------- ----------------------------------------
PUBLIC SCOTT ALTER
PUBLIC SCOTT DELETE
PUBLIC SCOTT INDEX
PUBLIC SCOTT INSERT
PUBLIC SCOTT SELECT
PUBLIC SCOTT UPDATE
PUBLIC SCOTT REFERENCES

7 rows selected.

old 1: drop procedure &1..dba_parse_$$
new 1: drop procedure scott.dba_parse_$$

Procedure dropped.

SQL>
===============================================================

that shows that it worked (the grants were in fact given) without logging in as the other user.

Rating

  (11 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

grant to other schema

Alejandro Camacho, May 29, 2001 - 12:45 pm UTC

Very useful. thanks

Doesnt it work in 9i

jianhui, July 03, 2003 - 5:35 pm UTC

FYI:
I can do grant of other's object to another user in 9i , but not in 8.1.7

It seems it was a design problem in previous versions, so in 9i , DBA is more like a real DBA now.

Creating procedure in another schema and grant execution right to some users.

Tommy, May 27, 2004 - 3:23 pm UTC

Hi Tom,

I know I can create objects in other schemas by create any procedure/table/view role. But how do I grant rights for other users to these objects?

drop user app_installer cascade
User dropped

create user app_installer identified by app_installer1
User created

drop role code_roll_role
Role dropped

create role code_roll_role
Role created

grant create any table, alter any table,create any procedure,alter any procedure,create any index, create any view
to code_roll_role
Grant succeeded

grant create session,code_roll_role to app_installer
Grant succeeded

connect app_installer/app_installer1;
Connecting as app_installer/app_installer1
/
create or replace procedure test_schema.tmp_proc1
as
v_cnt number;
begin
select count(*) into v_cnt from a_table_in_test_schema;
dbms_output.put_line('count = '||v_cnt);
end;
Procedure created

grant execute on test_schema.tmp_proc1 to user_a
ORA-01031: insufficient privileges
Original user/pwd reconnected


Tom Kyte
May 27, 2004 - 8:41 pm UTC

version?

RE: Creating procedure in another schema and grant execution right to some users

Tommy, May 28, 2004 - 9:43 am UTC

select * from v$version
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.0.1.0.0 - Production
PL/SQL Release 9.0.1.0.0 - Production
CORE 9.0.1.0.0 Production
TNS for Linux: Version 9.0.1.0.0 - Production
NLSRTL Version 9.0.1.0.0 - Production


Tom Kyte
May 28, 2004 - 11:38 am UTC

In 9.2 you can grant on schema A from schema B.

Prior to that, you will need to have that user (schema A) grant to schema B with the grant/admin option.




A reader, December 14, 2004 - 1:21 pm UTC

"In 9.2 you can grant on schema A from schema B.
Prior to that, you will need to have that user (schema A) grant to schema B with the grant/admin option"

Just curious...why was this added to 9.2? From a technical perspective, I am sure it was not a big deal to add? IIRC, there were security considerations in disallowing it in earlier versions?

In general, are there any caveats to using this feature? Using this someone with the DBA role can (in theory) start granting object privileges on any object to any user/role.

Somehow, the earlier behaviour seemed more "sane"! Comments?

Thanks

Tom Kyte
December 15, 2004 - 12:42 pm UTC

let me generalize: why is any feature added in any release?

because people asked for it in most cases.

this was something that was asked for.


(i was never one asking for it personally, it gives lots of control/capabilities -- it falls into the "ANY" grouping of privs -- really super powerful)

Alexander the ok, February 08, 2007 - 12:11 pm UTC

Hi,

To allow a user to access, modify objects in other schemas we use the with admin option. This however allows them to do so in any schema, correct? I was wondering if there is a way to limit this access to only a specific schema, instead of granting N number of individual statements for all the objects. That makes for a ton of sql statements.

I apologize in advance if you've covered this ad nauseam but I find Oracle security stuff impossibly hard to follow.
Tom Kyte
February 08, 2007 - 12:49 pm UTC

no, you don't use the admin option for that.

the admin option would allow someone that was granted a privilege to they themselves grant that privilege to others.

Alexander the ok, February 08, 2007 - 1:46 pm UTC

Right but isn't that expected? That's how it works for objects. If the dba grants select with admin to user a, then user a can grant to user b right? I guess I don't see the difference or what problem this would pose.
Tom Kyte
February 08, 2007 - 1:54 pm UTC

No, you wrote:

... To allow a user to access, modify objects in other schemas we use the with admin option. ...

that is not accurate. I'm not sure what you are trying to say.

Alexander the ok, February 08, 2007 - 2:00 pm UTC

Ok what I was trying to ask is,

grant select any table to joe with admin option;

will allow joe to select from a table in any schema right?

I want to allow joe to select from any table in a specific schema.
Tom Kyte
February 08, 2007 - 2:16 pm UTC

there is no such capability to "grant select on schema", you grant on individual schema objects.

Alexander the ok, February 08, 2007 - 3:38 pm UTC

Ok that's fine. I'm asking because I am having a problem with grants supposedly disappearing when I drop a schema and import objects back in from a dump. Oracle does not revoke grants to a role that belong to objects that are dropped via drop user cascade correct?

The documentation says roles are not dropped that are created by the dropped user but It doesn't mention anything about grants. Thanks a lot.
Tom Kyte
February 08, 2007 - 4:28 pm UTC

you are really confusing here - this question is going round and round and where it stops, no one will know.

if you drop a schema, everything goes away. everything granted to it.

if you import a schema level import, - it is expecting the user to exist, with all of the grants.

the import won't grant things TO the user, it'll grant things the user granted.

Alexander the ok, February 08, 2007 - 5:48 pm UTC

Yeah sorry I was getting reports of things happening that actually did not, so I was second guessing myself about how stuff works.

Admin_option

Helen Anderson, September 23, 2010 - 11:19 pm UTC

I am trying to update dba_role_privs.admin_option & default_role for a user, but seem to be running into some issues, can you help ....

update dba_role_privs
set ADMIN_OPTION ='NO'
WHERE GRANTEE = UPPER('wongm3')
AND ADMIN_OPTION IN ('RPD_ALL','RPD_USER');
commit;


Tom Kyte
September 27, 2010 - 10:12 am UTC

You cannot update the data dictionary - ever.

You use DDL to modify the dictionary. You will use the REVOKE/GRANT commands for this operation.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library