www.oradev.com
  Database   Sql   Functions   Packages   Performance   Books   Oracle   Other   About   XML   ORA-messages
  grant privileges in Oracle.

Database/Sql

Oracle Regular Expressions
Timestamp
SQL Date format
String concatenation
Loop in pl/sql
SQL IN-clause
Regular Expressions Examples
Flashback query
Grant/revoke privileges
Sequence
Rename tables, columns
Insert into Oracle
Database name
Table with sequenced numbers
Oracle connect by
Add columns to table


  OraDev.com

GRANT/REVOKE privileges in Oracle.

With the GRANT statement you can grant:
  • System privileges to users and roles.
  • Roles to users and roles. Both privileges and roles are either local, global, or external.
  • Object privileges for a particular object to users, roles, and PUBLIC.

To grant a system privilege, you must either have been granted the system privilege with the ADMIN OPTION or have been granted the GRANT ANY PRIVILEGE system privilege.

To grant a role, you must either have been granted the role with the ADMIN OPTION or have been granted the GRANT ANY ROLE system privilege, or you must have created the role.

To grant an object privilege, you must own the object, or the owner of the object must have granted you the object privileges with the GRANT OPTION, or you must have been granted the GRANT ANY OBJECT PRIVILEGE system privilege. If you have the GRANT ANY OBJECT PRIVILEGE, then you can grant the object privilege only if the object owner could have granted the same object privilege. In this case, the GRANTOR column of the DBA_TAB_PRIVS view displays the object owner rather than the user who issued the GRANT statement.


Syntax

System privileges
grant (system privilege/role/ALL PRIVILEGES) to (user/role/PUBLIC) [with admin option];
For example: grant create table to user1; grant

Object privileges
For example: grant select on emp to user1; grant select,insert,update,delete on emp to user2; grant select on emp to public;

To undo a granted privilege, you can use the REVOKE statement. Syntax: revoke (system privilege/role/ALL PRIVILEGES) from (user/role/PUBLIC);
revoke select,delete on emp from user2; revoke all on emp from user2;

System Privileges

The following system privileges can be granted:
ADVISOR Access the advisor framework through PL/SQL packages such as DBMS_ADVISOR and DBMS_SQLTUNE.
ADMINISTER SQL TUNING SET Create, drop, select (read), load (write), and delete a SQL tuning set owned by the grantee through the DBMS_SQLTUNE package.
ADMINISTER ANY SQL TUNING SET Create, drop, select (read), load (write), and delete a SQL tuning set owned by any user through the DBMS_SQLTUNE package.
CREATE ANY SQL PROFILE Accept a SQL Profile recommended by the SQL Tuning Advisor, which is accessed through Enterprise Manager or by the DBMS_SQLTUNE package.
DROP ANY SQL PROFILE Drop an existing SQL Profile.
ALTER ANY SQL PROFILE Alter the attributes of an existing SQL Profile.
CREATE CLUSTER Create clusters in the grantee's schema.
CREATE ANY CLUSTER Create a cluster in any schema. Behaves similarly to CREATE ANY TABLE.
ALTER ANY CLUSTER Alter clusters in any schema.
DROP ANY CLUSTER Drop clusters in any schema.
CREATE ANY CONTEXT Create any context namespace.
DROP ANY CONTEXT Drop any context namespace.
ALTER DATABASE Alter the database.
ALTER SYSTEM Issue ALTER SYSTEM statements.
AUDIT SYSTEM Issue AUDIT statements.
CREATE DATABASE LINK Create private database links in the grantee's schema.
CREATE PUBLIC DATABASE LINK Create public database links.
DROP PUBLIC DATABASE LINK Drop public database links.
DEBUG CONNECT SESSION Connect the current session to a debugger.
DEBUG ANY PROCEDURE Debug all PL/SQL and Java code in any database object. Display information on all SQL statements executed by the application. Note: Granting this privilege is equivalent to granting the DEBUG object privilege on all applicable objects in the database.
CREATE DIMENSION Create dimensions in the grantee's schema.
CREATE ANY DIMENSION Create dimensions in any schema.
ALTER ANY DIMENSION Alter dimensions in any schema.
DROP ANY DIMENSION Drop dimensions in any schema.
CREATE ANY DIRECTORY Create directory database objects.
DROP ANY DIRECTORY Drop directory database objects.
CREATE INDEXTYPE Create an indextype in the grantee's schema.
CREATE ANY INDEXTYPE Create an indextype in any schema and create a comment on an indextype in any schema.
ALTER ANY INDEXTYPE Modify indextypes in any schema.
DROP ANY INDEXTYPE Drop an indextype in any schema.
EXECUTE ANY INDEXTYPE Reference an indextype in any schema.
CREATE ANY INDEX Create in any schema a domain index or an index on any table in any schema.
ALTER ANY INDEX Alter indexes in any schema.
DROP ANY INDEX Drop indexes in any schema.
CREATE JOB Create jobs, schedules, or programs in the grantee's schema.
CREATE ANY JOB Create, alter, or drop jobs, schedules, or programs in any schema. Note: This extremely powerful privilege allows the grantee to execute code as any other user. It should be granted with caution.
CREATE EXTERNAL JOB Create in the grantee's schema an executable scheduler job that runs on the operating system.
EXECUTE ANY PROGRAM Use any program in a job in the grantee's schema.
EXECUTE ANY CLASS Specify any job class in a job in the grantee's schema.
MANAGE SCHEDULER Create, alter, or drop any job class, window, or window group.
CREATE LIBRARY Create external procedure or function libraries in the grantee's schema.
CREATE ANY LIBRARY Create external procedure or function libraries in any schema.
DROP ANY LIBRARY Drop external procedure or function libraries in any schema.
CREATE MATERIALIZED VIEW Create a materialized view in the grantee's schema.
CREATE ANY MATERIALIZED VIEW Create materialized views in any schema.
ALTER ANY MATERIALIZED VIEW Alter materialized views in any schema.
DROP ANY MATERIALIZED VIEW Drop materialized views in any schema.
QUERY REWRITE This privilege has been deprecated. No privileges are needed for a user to enable rewrite for a materialized view that references tables or views in the user's own schema.
GLOBAL QUERY REWRITE Enable rewrite using a materialized view when that materialized view references tables or views in any schema.
ON COMMIT REFRESH Create a refresh-on-commit materialized view on any table in the database. Alter a refresh-on-demand materialized on any table in the database to refresh-on-commit.
FLASHBACK ANY TABLE Issue a SQL Flashback Query on any table, view, or materialized view in any schema. This privilege is not needed to execute the DBMS_FLASHBACK procedures.
CREATE OPERATOR Create an operator and its bindings in the grantee's schema.
CREATE ANY OPERATOR Create an operator and its bindings in any schema and create a comment on an operator in any schema.
ALTER ANY OPERATOR Modify an operator in any schema.
DROP ANY OPERATOR Drop an operator in any schema.
EXECUTE ANY OPERATOR Reference an operator in any schema.
CREATE ANY OUTLINE Create public outlines that can be used in any schema that uses outlines.
ALTER ANY OUTLINE Modify outlines.
DROP ANY OUTLINE Drop outlines.
CREATE PROCEDURE Create stored procedures, functions, and packages in the grantee's schema.
CREATE ANY PROCEDURE Create stored procedures, functions, and packages in any schema.
ALTER ANY PROCEDURE Alter stored procedures, functions, or packages in any schema.
DROP ANY PROCEDURE Drop stored procedures, functions, or packages in any schema.
EXECUTE ANY PROCEDURE Execute procedures or functions, either standalone or packaged.
CREATE PROFILE Create profiles.
ALTER PROFILE Alter profiles.
DROP PROFILE Drop profiles.
CREATE ROLE Create roles.
ALTER ANY ROLE Alter any role in the database.
DROP ANY ROLE Drop roles.
GRANT ANY ROLE Grant any role in the database.
CREATE ROLLBACK SEGMENT Create rollback segments.
ALTER ROLLBACK SEGMENT Alter rollback segments.
DROP ROLLBACK SEGMENT Drop rollback segments.
CREATE SEQUENCE Create sequences in the grantee's schema.
CREATE ANY SEQUENCE Create sequences in any schema.
ALTER ANY SEQUENCE Alter any sequence in the database.
DROP ANY SEQUENCE Drop sequences in any schema.
SELECT ANY SEQUENCE Reference sequences in any schema.
CREATE SESSION Connect to the database.
ALTER RESOURCE COST Set costs for session resources.
ALTER SESSION Issue ALTER SESSION statements.
RESTRICTED SESSION Logon after the instance is started using the SQL*Plus STARTUP RESTRICT statement.
CREATE SYNONYM Create synonyms in the grantee's schema.
CREATE ANY SYNONYM Create private synonyms in any schema.
CREATE PUBLIC SYNONYM Create public synonyms.
DROP ANY SYNONYM Drop private synonyms in any schema.
DROP PUBLIC SYNONYM Drop public synonyms.
CREATE TABLE Create tables in the grantee's schema.
CREATE ANY TABLE Create tables in any schema. The owner of the schema containing the table must have space quota on the tablespace to contain the table.
ALTER ANY TABLE Alter any table or view in any schema.
BACKUP ANY TABLE Use the Export utility to incrementally export objects from the schema of other users.
DELETE ANY TABLE Delete rows from tables, table partitions, or views in any schema.
DROP ANY TABLE Drop or truncate tables or table partitions in any schema.
INSERT ANY TABLE Insert rows into tables and views in any schema.
LOCK ANY TABLE Lock tables and views in any schema.
SELECT ANY TABLE Query tables, views, or materialized views in any schema.
FLASHBACK ANY TABLE Issue a SQL Flashback Query on any table, view, or materialized view in any schema. This privilege is not needed to execute the DBMS_FLASHBACK procedures.
UPDATE ANY TABLE Update rows in tables and views in any schema.
CREATE TABLESPACE Create tablespaces.
ALTER TABLESPACE Alter tablespaces.
DROP TABLESPACE Drop tablespaces.
MANAGE TABLESPACE Take tablespaces offline and online and begin and end tablespace backups.
UNLIMITED TABLESPACE Use an unlimited amount of any tablespace. This privilege overrides any specific quotas assigned. If you revoke this privilege from a user, then the user's schema objects remain but further tablespace allocation is denied unless authorized by specific tablespace quotas. You cannot grant this system privilege to roles.
CREATE TRIGGER Create a database trigger in the grantee's schema.
CREATE ANY TRIGGER Create database triggers in any schema.
ALTER ANY TRIGGER Enable, disable, or compile database triggers in any schema.
DROP ANY TRIGGER Drop database triggers in any schema.
ADMINISTER DATABASE TRIGGER Create a trigger on DATABASE. You must also have the CREATE TRIGGER or CREATE ANY TRIGGER system privilege.
CREATE TYPE Create object types and object type bodies in the grantee's schema.
CREATE ANY TYPE Create object types and object type bodies in any schema.
ALTER ANY TYPE Alter object types in any schema.
DROP ANY TYPE Drop object types and object type bodies in any schema.
EXECUTE ANY TYPE Use and reference object types and collection types in any schema, and invoke methods of an object type in any schema if you make the grant to a specific user. If you grant EXECUTE ANY TYPE to a role, then users holding the enabled role will not be able to invoke methods of an object type in any schema.
UNDER ANY TYPE Create subtypes under any nonfinal object types.
CREATE USER Create users. This privilege also allows the creator to: Assign quotas on any tablespace. Set default and temporary tablespaces. Assign a profile as part of a CREATE USER statement.
ALTER USER Alter any user. This privilege authorizes the grantee to: Change another user's password or authentication method. Assign quotas on any tablespace. Set default and temporary tablespaces. Assign a profile and default roles.
DROP USER Drop users
CREATE VIEW Create views in the grantee's schema.
CREATE ANY VIEW Create views in any schema.
DROP ANY VIEW Drop views in any schema.
UNDER ANY VIEW Create subviews under any object views.
FLASHBACK ANY TABLE Issue a SQL Flashback Query on any table, view, or materialized view in any schema. This privilege is not needed to execute the DBMS_FLASHBACK procedures.
MERGE ANY VIEW If a user has been granted the MERGE ANY VIEW privilege, then for any query issued by that user, the optimizer can use view merging to improve query performance without performing the checks that would otherwise be performed to ensure that view merging does not violate any security intentions of the view creator. See also Oracle Database Reference for information on the OPTIMIZER_SECURE_VIEW_MERGING parameter and Oracle Database Performance Tuning Guide for information on view merging.
ANALYZE ANY Analyze any table, cluster, or index in any schema.
AUDIT ANY Audit any object in any schema using AUDIT schema_objects statements.
CHANGE NOTIFICATION Create a registration on queries and receive database change notifications in response to DML or DDL changes to the objects associated with the registered queries. Please refer to Oracle Database Application Developer's Guide - Fundamentals for more information on database change notification.
COMMENT ANY TABLE Comment on any table, view, or column in any schema.
EXEMPT ACCESS POLICY Bypass fine-grained access control. Caution: This is a very powerful system privilege, as it lets the grantee bypass application-driven security policies. Database administrators should use caution when granting this privilege.
FORCE ANY TRANSACTION Force the commit or rollback of any in-doubt distributed transaction in the local database. Induce the failure of a distributed transaction.
FORCE TRANSACTION Force the commit or rollback of the grantee's in-doubt distributed transactions in the local database.
GRANT ANY OBJECT PRIVILEGE Grant any object privilege that the object owner is permitted to to grant. Revoke any object privilege that was granted by the object owner or by some other user with the GRANT ANY OBJECT PRIVILEGE privilege.
GRANT ANY PRIVILEGE Grant any system privilege.
RESUMABLE Enable resumable space allocation.
SELECT ANY DICTIONARY Query any data dictionary object in the SYS schema. This privilege lets you selectively override the default FALSE setting of the O7_DICTIONARY_ACCESSIBILITY initialization parameter.
SELECT ANY TRANSACTION Query the contents of the FLASHBACK_TRANSACTION_QUERY view. Caution: This is a very powerful system privilege, as it lets the grantee view all data in the database, including past data. This privilege should be granted only to users who need to use the Oracle Flashback Transaction Query feature.
SYSDBA Perform STARTUP and SHUTDOWN operations.
CREATE DATABASE
ARCHIVELOG and RECOVERY
CREATE SPFILE Includes the RESTRICTED SESSION privilege.
SYSOPER Perform STARTUP and SHUTDOWN operations.
ALTER DATABASE open, mount, or back up.
ARCHIVELOG and RECOVERY.
CREATE SPFILE. Includes the RESTRICTED SESSION privilege.
CONNECT, RESOURCE, and DBA These roles are provided for compatibility with previous versions of Oracle Database. You can determine the privileges encompassed by these roles by querying the DBA_SYS_PRIVS data dictionary view. Note: Oracle recommends that you design your own roles for database security rather than relying on these roles. These roles may not be created automatically by future versions of Oracle Database.
DELETE_CATALOG_ROLE EXECUTE_CATALOG_ROLE SELECT_CATALOG_ROLE These roles are provided for accessing data dictionary views and packages.
EXP_FULL_DATABASE provided for convenience in using the export utility.
IMP_FULL_DATABASE provided for convenience in using the import utility.
AQ_USER_ROLE
AQ_ADMINISTRATOR_ROLE You need these roles to use Oracle Advanced Queuing.
SNMPAGENT This role is used by the Enterprise Manager Intelligent Agent.
RECOVERY_CATALOG_OWNER You need this role to create a user who owns a recovery catalog.



The following object privileges are possible:

ALTER Change the table/sequence definition with the ALTER TABLE/ALTER SEQUENCE statement.
DELETE Remove rows from the table/view with the DELETE statement. Note: You must grant the SELECT privilege on the table along with the DELETE privilege if the table is on a remote database.
DEBUG Access, through a debugger
INDEX Create an index on the table with the CREATE INDEX statement.
INSERT Add new rows to the table/view with the INSERT statement.
REFERENCES Create a constraint that refers to the table/view. You cannot grant this privilege to a role.
SELECT Query the table/view/sequence/materialized view with the SELECT statement.
UPDATE Change data in the table/view with the UPDATE statement.
UNDER Create a subview under this view. You can grant this object privilege only if you have the UNDER ANY VIEW privilege WITH GRANT OPTION on the immediate superview of this view.
EXECUTE Execute the procedure/function/object/indextype/operator directly, or access any program object declared in the specification of a package, or compile the object implicitly during a call to a currently invalid or uncompiled function or procedure. This privilege does not allow the grantee to explicitly compile using ALTER PROCEDURE or ALTER FUNCTION. For explicit compilation you need the appropriate ALTER system privilege.
ON COMMIT REFRESH Create a refresh-on-commit materialized view on the specified table.
QUERY REWRITE Create a materialized view for query rewrite using the specified table.
READ Read files in the directory.
WRITE Write files in the directory. This privilege is useful only in connection with external tables. It allows the grantee to determine whether the external table agent can write a log file or a bad file to the directory. Restriction: This privilege does not allow the grantee to write to a BFILE.