472,981 Members | 1,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 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 8500

"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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.