Roles Granted to Users
To determine roles granted to specific users, query the `DBA_ROLE_PRIVS` view:
SELECT
GRANTEE,
GRANTED_ROLE
FROM
DBA_ROLE_PRIVS
WHERE
GRANTEE IN ('USER1', 'USER2');
Object Privileges of the Roles
Once you have the roles for the users, you can find out the object privileges for those roles using the `DBA_TAB_PRIVS` view:
SELECT
GRANTEE AS ROLE_NAME,
OWNER,
TABLE_NAME,
PRIVILEGE
FROM
DBA_TAB_PRIVS
WHERE
GRANTEE IN (
SELECT GRANTED_ROLE
FROM DBA_ROLE_PRIVS
WHERE GRANTEE IN ('USER1', 'USER2')
);
This will give you the object-level privileges (like `SELECT`, `UPDATE`, etc.) that each of the roles has on database tables, views, etc.
System Privileges of the Roles
For system-level privileges that each role has, query the `DBA_SYS_PRIVS` view:
SELECT
GRANTEE AS ROLE_NAME,
PRIVILEGE
FROM
DBA_SYS_PRIVS
WHERE
GRANTEE IN (
SELECT GRANTED_ROLE
FROM DBA_ROLE_PRIVS
WHERE GRANTEE IN ('USER1', 'USER2')
);
This gives you system privileges like `CREATE SESSION`, `ALTER SYSTEM`, etc., that each role possesses.
Remember, if you want a full picture of the roles' permissions, you'll also need to consider roles that are granted to other roles. This requires recursive querying of the `DBA_ROLE_PRIVS` view.
Lastly, if you don't have access to the `DBA_` prefixed views, you might have access to their `ALL_` or `USER_` counterparts. These provide similar information but are limited in scope based on your permissions.
Always ensure you have the necessary permissions to access these DBA views and exercise caution when working with database permissions.
REMOVE ACCESS
REVOKE privilege_name ON object_name FROM role_name;
REVOKE SELECT ON EMPLOYEES FROM HR_ROLE;
--Rerunnable
DECLARE
v_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO v_count
FROM DBA_TAB_PRIVS
WHERE TABLE_NAME = 'YOUR_TABLE_NAME'
AND PRIVILEGE = 'YOUR_PRIVILEGE'
AND GRANTEE = 'YOUR_USER';
IF v_count > 0 THEN
EXECUTE IMMEDIATE 'REVOKE YOUR_PRIVILEGE ON YOUR_TABLE_NAME FROM YOUR_USER';
END IF;
END;
/