I need help to build a query returning the data in the following way. I think a hierarchical query could be of help to it. But I'm not sure how to use it in my case.
For instance, I have following data
Grantee Role
------- ------
User_1 Role_4
Role_4 Role_1
Role_4 Role_2
Role_4 Role_3
User_2 Role_5
User_2 Role_6
What I need is to return all roles users have been granted directly or indirectly. I know how to query all roles of a single user
SELECT DISTINCT GRANTED_ROLE FROM DBA_ROLE_PRIVS
START WITH GRANTEE=UPPER('&&USERNAME')
CONNECT BY PRIOR GRANTED_ROLE=GRANTEE
The query result for the user User_1 is
ROLE_1
ROLE_2
ROLE_3
ROLE_4
But I can't figure it out how to return all roles for multiple users. For instance I wish to get a result set in the following way
Grantee Role
------- ------
User_1 Role_4
User_1 Role_1
User_1 Role_2
User_1 Role_3
User_2 Role_5
User_2 Role_6