How to check the privileges (DDL,DML,DCL) on objects assigned to Schema, Roles in oracle Database?

10,658

A little brief about data dictionary view prefix:

ALL_    -Describes PUBLIC Object grants.
USER_   -Describes current user Object grants.
DBA_    -Describes all object grants in the database.

Useful views information:

ROLE_ROLE_PRIVS     -describes the roles granted to other roles. 
ROLE_SYS_PRIVS      -describes system privileges granted to roles.
ROLE_TAB_PRIVS      -describes table privileges granted to roles. 
DBA_ROLE_PRIVS      -describes the roles granted to all users and roles in the database.
DBA_SYS_PRIVS       -describes system privileges granted to users and roles.
DBA_TAB_PRIVS       -describes all object grants in the database.
DBA_COL_PRIVS       -describes all column object grants in the database.

To know more about PRIVS views visit here.

Queries:

-About user/schema status

select username,account_status, created from dba_users where username in ('SCOTT');

-Check the assigned roles to role and schema

select * from DBA_ROLE_PRIVS where grantee in ('SCOTT','RESOURCE');

-Check the role privileges

select * from ROLE_ROLE_PRIVS where role in ('RESOURCE','CONNECT');    
select * from ROLE_TAB_PRIVS  where role in ('RESOURCE','CONNECT');
select * from ROLE_SYS_PRIVS  where role in ('RESOURCE','CONNECT');

Pseudo Code:
select 'grant '||privilege||' to ROLE_SLAVE;' from ROLE_SYS_PRIVS where role in ('RESOURCE','CONNECT');
select 'grant '||privilege||' to ROLE_SLAVE;' from ROLE_TAB_PRIVS where role in ('RESOURCE','CONNECT');

-Check privileges of granted objects for schema

select * from DBA_SYS_PRIVS where grantee in ('SCOTT');
select * from DBA_TAB_PRIVS where grantee in ('SCOTT');
select * from DBA_COL_PRIVS where grantee in ('SCOTT');

Pseudo Code: 
select 'grant '||privilege||' to SCOTT_SLAVE;' from DBA_SYS_PRIVS where grantee in ('SCOTT');
select 'grant '||privilege||' on '||owner||'.'||table_name||' to SCOTT_SLAVE;' from DBA_TAB_PRIVS where grantee in ('SCOTT');
select 'grant '||privilege||' ('||column_name||') '||' on '||owner||'.'||table_name||' to SCOTT_SLAVE;' from DBA_COL_PRIVS where grantee in ('SCOTT');

Thank You!

Share:
10,658

Related videos on Youtube

Rajesh
Author by

Rajesh

Over 9+ years of IT experience in implementation, Development of app and web applications, Task automation, System design, Data structures & algorithms, Data warehouse solutions, Data modeling & analytics, Cloud Services, and Support.

Updated on June 04, 2022

Comments

  • Rajesh
    Rajesh almost 2 years

    Most of the time we struggle with silly things to get the detail of privileges on Schema, Role and their Objects and try to find some easy way to get all the detail about it along with there pseudo queries code to generate grant statements in bulk for further execution. So here we are to get it.