At first the three can be confusing to differentiate. Lets define them first:
So we can assert a good ammount of control over the user here, by bundling privileges into roles and then granting those roles to user accounts, and then further controlling the resource usage of the account with a profile. In almost all cases the "default" profile will be used, so lets look at roles in more depth.
Lets list some of the predefined roles that Oracle makes avalible to us:
By utilizing the data dictionary (Oracle configuration tables) we can check the current set of roles and privileges. The DBA_ROLES table contains all the roles avalible and DBA_ROLE_PRIVS contains the user-to-role mappings. If your not sure which roles are assigned to a user, check this table.
SQL> select * from DBA_ROLES; ROLE PASSWORD ------------------------------ -------- CONNECT NO RESOURCE NO DBA NO SELECT_CATALOG_ROLE NO EXECUTE_CATALOG_ROLE NO ... SQL> select * from DBA_ROLE_PRIVS; GRANTEE GRANTED_ROLE ADM DEF ------------------------------ ------------------------------ --- --- BEN CONNECT NO YES DBA OLAP_DBA NO YES DBA XDBADMIN NO YES ....
Like we used when creating the user, we can use the GRANT SQL statement to grant new roles to a user. We can also use the REVOKE statement to remove a role from the user.
SQL> grant resource to ben; Grant succeeded. SQL> select * from DBA_ROLE_PRIVS where grantee = 'BEN'; GRANTEE GRANTED_ROLE ADM DEF ------------------------------ ------------------------------ --- --- BEN CONNECT NO YES BEN RESOURCE NO YES SQL> revoke resource from ben; Revoke succeeded. SQL> select * from DBA_ROLE_PRIVS where grantee = 'BEN'; GRANTEE GRANTED_ROLE ADM DEF ------------------------------ ------------------------------ --- --- BEN CONNECT NO YES SQL>