Seeking Oracle out of the matrix

Google
 
Web aboutoracle.blogspot.com
Oracle New Articles
Oracle Critical Patches
Oracle jDeveloper News
Oracle Blogs of interest


This blog records my personal experience.
Latest news from the front
               

Thoughts about oracle Author's note : Thank you all for your supporting letters. You have been a motivation to this web spot's posting. I wish you all the very best for you and your families for the new year.
Interested to know about a next post? You can suscribe to my RSS feed
HOW TO:

TIP: Grant select on all user tables to another user
Monday, December 04, 2006
This is one of the number one issues for a DBA. Well, the good news is that it has become really easy to do this.

My methodology is to create public synonyms for the user tables and grant access to the user tables underlying those synonyms.

Example:
User : Tom
Table : Products, PriceList
Purpose : Grant access to user Bob

Here is how to do it:

Create public synonyms for tables Products, PriceList
Normally User Tom sees them as Products and PriceList. Even if you grant access to those tables to user Bob, he still gonna access them as Tom.Products and Tom.PriceList
To allow user Bob to access those tables as Products and PriceList, you must create public synonyms. Public synonyms can be created under SYS so log in to your SQL Worksheet as SYS and type the following:


SET SERVEROUTPUT ON
begin
dbms_output.enable(1000000);
for x in ( select table_name from DBA_ALL_TABLES where owner='TOM' )
loop
dbms_output.put_line('CREATE OR REPLACE PUBLIC SYNONYM ' x.table_name ' FOR Tom.' x.table_name);
EXECUTE IMMEDIATE ('CREATE OR REPLACE PUBLIC SYNONYM ' x.table_name ' FOR Tom.' x.table_name);
end loop;
end;


You will find this piece of source code really useful when you will apply it in a production system with hundreds or thousands of tables.
What it does is apply for every table belonging to user Tom a public synonym which is the name of the table (but ommiting the Tom. part).

Now what you must do is grant access to user Bob on those tables

In the following piece of code i will grant select on a role. It's better to work with roles because they can be easily implemented to a user and then you can customize user rights independently

Here is the source :


SET SERVEROUTPUT ON
begin
dbms_output.enable(1000000);
for x in ( select table_name from DBA_ALL_TABLES where owner='Tom' )
loop
dbms_output.put_line('grant select on ' x.table_name ' to myrole');
execute immediate 'grant select on ' x.table_name ' to myrole';
end loop;
end;


After that, you will assign the role to your user(s) and that's it.

You have granted access to those tables to your second user with a few lines of code.

posted by Admin @ 6:47 PM  
add to del.icio.us Digg it! Furl this! add to reddit! add to dzone!
1 Comments:
Post a Comment
<< Home

About Me

Name: John Galanopoulos
Home: The NeverLands
About Me: A source code wonderer since the early 80s with my first ZX81 by Sinclair, home computer.
See my complete profile
Previous Post
Archives
Links
ΣΚΛΗΡΥΝΣΗ ΚΑΤΑ ΠΛΑΚΑΣ - ΕΓΚΕΦΑΛΟΣ - ΕΓΚΕΦΑΛΟΓΡΑΦΗΜΑ - ΑΝΟΙΑ - ΝΕΥΡΟΛΟΓΟΣ - ΨΥΧΙΑΤΡΟΣ - ΛΟΙΜΩΔΗΣ ΜΟΝΟΠΥΡΗΝΩΣΗ - ΠΑΡΚΙΝΣΟΝ - ΑΓΧΟΣ - ΚΑΤΑΘΛΙΨΗ - ALZHEIMER - EPSTEIN BARR Eurolife
Email notification

Enter your email address and get notified whenever there is a new post:

Delivered by FeedBurner

This website abides by a strict policy : no spam, just posts; and that's a promise.

Powered by

Free Blogger Templates

BLOGGER


Register for a skinnyscore at www.blogskinny.com and increase traffic
Software Blogs -  Blog Catalog Blog Directory

© 2005 Seeking Oracle out of the matrix Template by Isnaini Dot Com