Solved

Revoke access on all tables

Posted on 2004-04-20
4
1,761 Views
Last Modified: 2007-12-19
I have some 2000 tables with different previlages granted on them can use one statment like below to revoke all of them

revoke all on <tablename> from <username>;

I will have to execute above statement for each table, instaed can i use something like ALL or anyother keywords.

Thanks,
rajeev
0
Comment
Question by:rajeevrc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
seazodiac earned 250 total points
ID: 10872101
you cannot do it with ALL
but you can do it with one script:


here is the short one:

set termout off
set feedback off
set heading off
set trimspool on
set linesize 200
set pagesize 0

spool revoke_all.sql

select 'revoke all on ' || table_name|| '  from <user_name> ;' from all_tables where owner not in ('SYS', 'SYSTEM');

spool off
@revoke_all.sql


save this in a file , say test.sql

and call this file in sqlplus

SQL> @test.sql



that will be it


0
 
LVL 1

Expert Comment

by:ora-dba
ID: 10872564
The above solution will work fine. Another way to do this would be with a PL/SQL block

declare
  user_name varchar2(30) := 'SCOTT'; -- the name of the user that you like to revoke privileges from
begin
  for rec in (select table_name
                 from all_tables
                 where owner not in ('SYS','SYSTEM')) loop
    execute immediate 'revoke all on '||rec.table_name||' from '||user_name;
  end loop;
end;
/
0
 
LVL 8

Expert Comment

by:annamalai77
ID: 10874729
hi there

well u can use a pl/sql block to solve ur problem for all the users. well what ora-dba has given , u have to hard code the username.

u can go by seazodiac method since it will be easy to do it.
also u can get the username at runtime also.

regards
annamalai

0
 
LVL 1

Expert Comment

by:ora-dba
ID: 10876695
Dear annamalai,
you can easily change my code so that the username doesn't have to be hard coded:

define user_name = "SCOTT"

begin
  for rec in (select table_name
                 from all_tables
                 where owner not in ('SYS','SYSTEM')) loop
    execute immediate 'revoke all on '||rec.table_name||' from &user_name';
  end loop;
end;
/
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MULTIPLE DATE QUERY 15 103
Email query results in HTML 6 38
Oracle database T-1 Setup 7 30
error in oracle form 11 28
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question