Oracle DB – How to select user roles

You can use this SQL script giving the username as argument.

Example:

sqlplus myuser@myDBName @select_roles.sql user1
/* select_roles.sql Script */
select
  lpad(' ', 2*level) || granted_role "User and roles"
from
  (
  /* THE USERS */
    select
      null     grantee,
      username granted_role
    from
      dba_users
    where
      username like upper('%&1%')
  /* THE ROLES TO ROLES RELATIONS */
  union
    select
      grantee,
      granted_role
    from
      dba_role_privs
  )
start with grantee is null
connect by grantee = prior granted_role;

Leave a Reply

Your email address will not be published. Required fields are marked *