Wednesday, 3 December 2025

Oracle Role Creation With Examples

Oracle Role Creation With Examples

In this blog we will discuss how to create a role in Oracle Database and
how to give rights to users using that role.

Roles are very useful because instead of giving permissions to each user
one by one, we can put all permissions inside a role and then assign
that role to users.

Create Role 

Example: CREATE ROLE view_role;

Grant Privileges to Role 

Example: GRANT CREATE SESSION TO view_role;
GRANT SELECT ANY TABLE TO view_role;

We can also give table-level rights. Example: GRANT SELECT ON
hr.employees TO view_role;

Create User 

Example: CREATE USER rohit IDENTIFIED BY rohit123;

Grant Role to User 

Example: GRANT view_role TO rohit;

Revoke Privileges from Role

Example: REVOKE SELECT ANY TABLE FROM
view_role;

Drop Role

Example: DROP ROLE view_role;

Conclusion Using roles in Oracle is very helpful for managing user
permissions. Instead of granting many privileges to each user
separately, it is better to create one role, assign all required rights
to that role, and then grant the role to users. This makes
administration easy and clean.