473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Granting the privileges of existing objects within a schema to a new role

Ted
How do I grant all privileges for a schema that has a large number of
existing tables, procedures, functions, etc to a newly created role,
without having to issue a grant statement for each object and each
privilege? I want the role to have all of the rights of the schema
owner.

Is there any kind of blanket granting of all privileges to a role?
Jul 19 '05 #1
2 8535

"Ted" <st******@ceva.net> wrote in message
news:39**************************@posting.google.c om...
| How do I grant all privileges for a schema that has a large number of
| existing tables, procedures, functions, etc to a newly created role,
| without having to issue a grant statement for each object and each
| privilege? I want the role to have all of the rights of the schema
| owner.
|
| Is there any kind of blanket granting of all privileges to a role?

Like 'GRANT SELECT TO xxx ON SCHEMA SCOTT'? Good idea, but doesn't exist.

You can, however, right PL/SQL to loop through all objects in a schema and
grant appropriate privileges to the target role

Something like:

procedure grant_all_objects(ip$role in varchar2)
for r1 in (select object_type, object_name from user_objects where
object_type in .... )
loop
case
when r1.object_type = 'TABLE'
then execute immediate 'grant select on ' || r1.object_name || ' to
' || ip$role;
when r1.object_type in ('PROCEDURE','FUNCTION'...

++ mcs
Jul 19 '05 #2
Ted wrote:
How do I grant all privileges for a schema that has a large number of
existing tables, procedures, functions, etc to a newly created role,
without having to issue a grant statement for each object and each
privilege? I want the role to have all of the rights of the schema
owner.

Is there any kind of blanket granting of all privileges to a role?


-- Try something like:
rem This script performs dynamic granting of tables,views,sequences to
rem users/roles/PUBLIC. This script needs to be run as the owner
rem of the objects you are granting to.

rem s_user - List of users/roles to grant to. Can be comma seperated.

set verify off
set pause off
set doc off
set heading off

accept s_user prompt 'Enter USERNAME,ROLE, or PUBLIC to grant to : '

prompt

show user

prompt 'Granting SELECT,INSERT,UPDATE,DELETE only to &s_user'
prompt

DECLARE
l_sql varchar2(254);
cursor_id integer;
result integer;

l_target_user varchar2(80) := '&s_user';

cursor get_tab is
select table_name from user_tables ;

cursor get_view is
select view_name from user_views;

cursor get_seq is
select sequence_name from user_sequences;

BEGIN

cursor_id:=dbms_sql.open_cursor;

/* Tables first */

FOR tab_rec in get_tab LOOP

l_sql := 'grant select,insert,update,delete on
'||tab_rec.table_name||' to '||l_target_user;
dbms_sql.parse(cursor_id,l_sql,1);
result := dbms_sql.execute(cursor_id);

END LOOP;

/* Views */

FOR view_rec in get_view LOOP

l_sql := 'grant select,insert,update,delete on
'||view_rec.view_name||' to '||l_target_user;
dbms_sql.parse(cursor_id,l_sql,1);
result := dbms_sql.execute(cursor_id);

END LOOP;

/* Sequences */

FOR seq_rec in get_seq LOOP

l_sql := 'grant select on '||seq_rec.sequence_name||' to
'||l_target_user;
dbms_sql.parse(cursor_id,l_sql,1);
result := dbms_sql.execute(cursor_id);

END LOOP;

dbms_sql.close_cursor(cursor_id);

END;
/

-- add loops for each type (e.g., packages, etc.)
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DC_DBA | last post by:
I want to 'grant sysdba to a user' for an application. (At least that is what I believe so far after having had this problem dumped on me 2 days ago.) The support we get from the application vendor...
4
by: Amardeep Verma | last post by:
Hi, I have a quick question. Which role/privileges are required before a user can give the statement "GRANT ALL PRIVILEGES"? Thanking you in Advance Have a nice day
4
by: Wade Chy | last post by:
Hi All I am in a situation where I have to grant select privileges on tables owned by a different owner to a specific role. I am logged in as system/sysdba. I have created a new role...
1
by: Amin Schoeib | last post by:
Hi, I have a problem with permissions for SELECT. Here is what I did: test=> GRANT SELECT ON "poi"."fondsstamm" TO "flex"; GRANT test=> \dp fondsstamm; Access privileges for database...
2
by: LazyAnt | last post by:
Hello, I have DB2 v8.1 for Linux for a class environment; each user has his/her own database as dbadm and they are suppose to study queries from another database. They have the right...
5
by: Rahul B | last post by:
Hi, I am having the following issues while trying to restrict the current user from creating any objects. Below is the privileges for the user and response when i try to create a table in that...
3
by: Rahul B | last post by:
Hi, I want to grant only the connect, select, insert, update privileges on all the tables of a schema to a particular user/group Initially, i had revoked all the privileges from public. It...
1
by: gdev | last post by:
Having some trouble getting my head around setting access to specific schemas- here's my problem: I've created a specific schema that I only want certain users to control Problem: Even...
1
by: Ted | last post by:
How do I grant all privileges for a schema that has a large number of existing tables, procedures, functions, etc to a newly created role, without having to issue a grant statement for each object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.