Home > Ask the Oracle Experts > PL/SQL Questions & Answers > Script to revoke access from user
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Script to revoke access from user

Greg Williams EXPERT RESPONSE FROM: Greg Williams

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 05 March 2007
I'm trying to write a script to revoke all access from any given user. I've done the following so far, but can't figure out all the errors -- can you help?
VARIABLE g_message varchar2(50);
ACCEPT p_ID PROMPT 'Please enter the desired ID to revoke privileges:'

BEGIN
for rec in (Select distinct privilege, grantee, Table_name
From dba_tab_privs
Where grantee = p_ID;) loop

revoke rec.privilege on rec.Table_name from rec.grantee;
END;
/
print g_message;

>
EXPERT RESPONSE
Hi,

The problem that you are having with your anonymous PL/SQL block is that the revoke command is not valid in PL/SQL. Therefore, you will have to execute it dynamically using the EXECUTE IMMEDIATE statement. The statement below shows how to use the execute immediate statement:

      execute immediate ('revoke '||rec.privilege||' on
'||rec.table_name||' from '||rec.grantee);
Also you will need an "End Loop." Your block should look like this:
    begin
    for rec in (select distinct privilege, grantee, table_name
                    from dba_tab_privs
                    where grantee = p_id)
    loop
       execute immediate ('revoke '||rec.privilege||' on
'||rec.table_name||' from '||rec.grantee);
    end loop;
end;
Note: To view your PL/SQL errors you can use the following statement:
      select * from user_errors;


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
PL/SQL
Converting Long Raw to Blob
Parsing in Oracle
ORA-01422 error when procedure returns more than one row
Definition of force view
ORA-04082: NEW or OLD references not allowed in table level triggers
Execute SQL statement from table in other schema
PL/SQL procedure to load CSV file into database table
Finding size of files in BLOB datatype
Expression is of wrong type
Sorting a clob column

Oracle PL/SQL
Oracle's free SQL Developer adds database migration tool
Confused about Oracle certification exams
ORA-01422 error when procedure returns more than one row
Calling procedure inside another procedure in anonymous block
How to import comma-delimited text file to Oracle table
Oracle updates Microsoft developer tools
PLS-00103 errors
PL/SQL do's and don't's: Five questions with Steven Feuerstein
Definition of force view
ORA-04082: NEW or OLD references not allowed in table level triggers

Oracle error messages
ORA-12560 error with Oracle 10g Instant Client
Unable to view Oracle tables in NetBeans
IMP-00017 error message with Oracle import
Can't open database after failed backup export
Query on dblink returning ORA-12545 error
RMAN not working at command prompt
Unique constraint violations, "parent key not found" errors
Insufficient privileges error when creating stored procedure
IMP-00010 error with import from 10g to 9i
ORA-12801 error while loading seed data

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
PL/SQL  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts