Skip to Main Content
  • Questions
  • Granting select on all tables and views of one user to other

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Ravi.

Asked: December 19, 2000 - 12:56 pm UTC

Last updated: March 29, 2019 - 5:07 pm UTC

Version: 815

Viewed 50K+ times! This question is

You Asked

Tom,

I have a user with x tables any y views. I wish to grant select on all the tables and views owned by this user to another user. Is there any thing like "select any table" for this purpose.

I am thinking to implement by granting the select on all the tables and views to role and then granting the role to the second user. But this way, if I create a new table/view for the first user, then I may have to add this privs to the role again. So I want to be more dynamic.

That is why I am coming to the expert(you). Will you please give the best approach for this.

Thanks
Ravi

and Tom said...

Well, there is no grant that allows a user or role access to all objects in a schema like that however ...


If you start out granted select on all tables/views to some user/role right now - I have a DDL trigger that works in Oracle8i and up that will make it so new objects are granted in a reasonable amount of time to that user/role.

See
</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:646423863863 <code>for how this might work.


Rating

  (4 ratings)

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

Comments

Granting select, insert, update, delete on all tables of one user to a role

an, January 30, 2003 - 10:53 am UTC

Hi Tom:

if i am not worry about new tables that will be created in the future from a user, now i need to create a role, that should have all select, update, insert, delete privs from the user, if it's no syntax as grant select, update, ... from the user to the role, how can i create a procedure that will grant select, update, insert, delete privs from the user to the role?
thanks,

Tom Kyte
January 30, 2003 - 11:30 am UTC

begin
for x in ( select tname from tab )
loop
execute immediate 'grant select, insert, update, delete on ' || x.tname ||
' to whatever_role';
end loop;
end;


need to add some more info.

Bhanu Prashanthi M, March 25, 2004 - 5:35 am UTC

The query is of great help. It will be more useful if we add that the grant should be on valid objects only.

A reader, June 02, 2004 - 4:10 pm UTC

This is exactly what I needed...(I am not sure if this is suitable for ORACLE)...I modified it to user USER_TABLES and it worked like a charm!
thanks,

Thanks for this!

Wools83, March 27, 2019 - 9:46 pm UTC

Excellent! Just what I needed.

I modified it to work in Oracle 12c for just one schema:

begin
for x in ( select VIEW_NAME from DBA_VIEWS WHERE OWNER = '<SCHEMA_NAME>' )
loop
execute immediate 'grant select on <SCHEMA_NAME>.' || x.VIEW_NAME || ' to <ROLL_NAME>';
end loop;
end;


Chris Saxon
March 29, 2019 - 5:07 pm UTC

Glad we could help, thanks for sharing.

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