Thursday, March 16, 2017

Oracle 11gR2 -- Find All Object Privileges which a User has

Problem

You want to find all object privileges that a specific user has.

Solution

WITH t AS
  (SELECT '<user_name>' user_name FROM dual
  )
SELECT *
FROM dba_tab_privs
WHERE table_name LIKE '%'
AND (grantee =
  (SELECT user_name FROM t
  )
OR grantee IN
  (SELECT granted_role
  FROM dba_role_privs
    START WITH grantee =
    (SELECT user_name FROM t
    )
    CONNECT BY prior granted_role = grantee
  )
OR grantee = 'PUBLIC') ;

No comments: