← Users & Privileges
Oracle · Users & Privileges

How to check a user's privileges in Oracle (system, object, roles)

See a user's full privileges in Oracle: roles, system privileges, and object privileges, granted directly or through roles.

Tested on11g12c19c21c23ai26ai

The full privilege picture for one account, in three parts: the roles it holds, its system privileges, and its object privileges. Each privilege is shown whether it was granted directly or to a role the user has, and nested roles are expanded with a hierarchical query. Prompts for a username.

-- 1. Roles granted to the user (direct)
SELECT granted_role, admin_option, default_role
FROM   dba_role_privs
WHERE  grantee = UPPER('&&username')
ORDER  BY granted_role;

-- 2. System privileges: granted directly, or to a role the user has (nested roles expanded)
SELECT privilege, grantee AS granted_to
FROM   dba_sys_privs
WHERE  grantee = UPPER('&username')
   OR  grantee IN (SELECT granted_role
                   FROM   dba_role_privs
                   START  WITH grantee = UPPER('&username')
                   CONNECT BY PRIOR granted_role = grantee)
ORDER  BY privilege;

-- 3. Object privileges: granted directly, or to a role the user has
SELECT owner, table_name, privilege, grantee AS granted_to
FROM   dba_tab_privs
WHERE  grantee = UPPER('&username')
   OR  grantee IN (SELECT granted_role
                   FROM   dba_role_privs
                   START  WITH grantee = UPPER('&username')
                   CONNECT BY PRIOR granted_role = grantee)
ORDER  BY owner, table_name, privilege;
privilegesrolesdba_sys_privsdba_tab_privs