Solved

Revoke access on all tables

Posted on 2004-04-20
4
1,725 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
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
seazodiac earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now