DBA_TAB_PRIVS - Oracle Dictionary View com informações de privilégios nos objetos do sistema
Autor: Jorge Jeferson Ferreira Montalvão | Publicado: 2012-03-30T14:22:00-03:00


Olá

Veja esta situação: fui solicitado que levantasse todas as pessoas que tivessem permissão de DELETE em uma determinada tabela do nosso banco de dados Oracle.
Bem, a tabela DBA_TAB_PRIVS contém os privilégios sobre os objetos do banco de dados.

SQL&gt; SELECT COMMENTS
&nbsp; &nbsp; &nbsp; &nbsp;FROM DICTIONARY
&nbsp; &nbsp; &nbsp; WHERE TABLE_NAME = 'DBA_TAB_PRIVS';

COMMENTS
--------------------------------------------------------------------------------
All grants on objects in the database

SQL&gt; SELECT DISTINCT OBJECT_TYPE
&nbsp; &nbsp; &nbsp; &nbsp;FROM DBA_TAB_PRIVS ,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBA_OBJECTS &nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; WHERE DBA_TAB_PRIVS.TABLE_NAME = DBA_OBJECTS.OBJECT_NAME
&nbsp; &nbsp; &nbsp; ORDER BY DBA_OBJECTS.OBJECT_TYPE;

OBJECT_TYPE
-------------------
CONSUMER GROUP
DIRECTORY
EVALUATION CONTEXT
FUNCTION
INDEX
INDEXTYPE
JAVA CLASS
JAVA RESOURCE
JOB CLASS
LIBRARY
OPERATOR
PACKAGE
PACKAGE BODY
PROCEDURE
QUEUE
SEQUENCE
SYNONYM
TABLE
TYPE
TYPE BODY
VIEW

21 rows selected

SQL&gt; SELECT DISTINCT PRIVILEGE
&nbsp; &nbsp; &nbsp; &nbsp;FROM DBA_TAB_PRIVS
&nbsp; &nbsp; &nbsp; ORDER BY PRIVILEGE;

PRIVILEGE
----------------------------------------
ALTER
DEBUG
DELETE
DEQUEUE
EXECUTE
FLASHBACK
INDEX
INSERT
ON COMMIT REFRESH
QUERY REWRITE
READ
REFERENCES
SELECT
UNDER
UPDATE
WRITE

16 rows selected

Então, um exemplo usando o esquema de teste HR, é este: verificar quem tem acesso a tabela EMPLOYEES:


SQL&gt; SELECT DBA_TAB_PRIVS.PRIVILEGE,
&nbsp; &nbsp; &nbsp; &nbsp;DBA_TAB_PRIVS.GRANTEE ROLE_OR_USER,
&nbsp; &nbsp; &nbsp; &nbsp;DBA_ROLE_PRIVS.GRANTEE USER_NAME
&nbsp; FROM DBA_TAB_PRIVS,
&nbsp; &nbsp; &nbsp; &nbsp;DBA_ROLE_PRIVS
&nbsp;WHERE DBA_TAB_PRIVS.TABLE_NAME = 'EMPLOYEES'
&nbsp; &nbsp;AND DBA_ROLE_PRIVS.GRANTED_ROLE(+) = DBA_TAB_PRIVS.GRANTEE
&nbsp;ORDER BY DBA_TAB_PRIVS.PRIVILEGE,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBA_TAB_PRIVS.GRANTEE


PRIVILEGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ROLE_OR_USER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USER_NAME
---------------------------------------- ------------------------------ ------------------------------
REFERENCES &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
SELECT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;



O usuário "OE" (Order Entry, esquema para exemplo de Ordem de Entrada) pode fazer SELECT e criar FOREIGN KEY que apontem para esta tabela.



Verificar quem tem acesso a tabela CUSTOMERS do esquema OE:




SQL&gt; SELECT DBA_TAB_PRIVS.PRIVILEGE,

&nbsp; &nbsp; &nbsp; &nbsp;DBA_TAB_PRIVS.GRANTEE ROLE_OR_USER,

&nbsp; &nbsp; &nbsp; &nbsp;DBA_ROLE_PRIVS.GRANTEE USER_NAME

&nbsp; FROM DBA_TAB_PRIVS,

&nbsp; &nbsp; &nbsp; &nbsp;DBA_ROLE_PRIVS

&nbsp;WHERE DBA_TAB_PRIVS.OWNER = 'OE'

&nbsp; &nbsp;AND DBA_TAB_PRIVS.TABLE_NAME = &nbsp;'CUSTOMERS'

&nbsp; &nbsp;AND DBA_ROLE_PRIVS.GRANTED_ROLE(+) = DBA_TAB_PRIVS.GRANTEE

&nbsp;ORDER BY DBA_TAB_PRIVS.PRIVILEGE,

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DBA_TAB_PRIVS.GRANTEE



PRIVILEGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ROLE_OR_USER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USER_NAME

---------------------------------------- ------------------------------ ------------------------------

SELECT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BI &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

SELECT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;