How to Use RBAC in Oracle

Galaxy Glossary

How do I use RBAC in Oracle to secure my tables?

RBAC in Oracle lets you bundle privileges into roles and assign those roles to users for simplified, secure access management.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Table of Contents

What is Oracle RBAC?

Role-Based Access Control (RBAC) in Oracle groups privileges into roles that you grant to users or applications. Roles simplify security reviews, reduce direct grants, and let you enable or disable permissions in one step.

Why choose roles over direct grants?

Roles scale better. Instead of granting SELECT on Customers to every analyst, you grant the privilege once to a role such as customer_ro and assign that role to all analysts.Revoking the role instantly removes access.

How do I create a role?

Use CREATE ROLE.Optionally protect the role with a password so only DBAs can enable it within a session.

CREATE ROLE customer_ro IDENTIFIED BY customer_ro_pwd;

Example: Read-only customer data role

CREATE ROLE customer_ro IDENTIFIED BY customer_ro_pwd;
GRANT SELECT ON Customers TO customer_ro;
GRANT SELECT ON Orders TO customer_ro;

How do I grant object privileges to a role?

After creating the role, grant table or view privileges just as you would to a user.

GRANT SELECT, UPDATE ON Products TO sales_ops;

How do I assign roles to users?

Grant the role to each user.You can make the role default so it is enabled automatically.

GRANT customer_ro TO analyst_jane; -- non-default
GRANT sales_ops TO seller_app WITH ADMIN OPTION;
ALTER USER analyst_jane DEFAULT ROLE customer_ro;

How do I limit role activation?

Protect a role with a password or make it NOT IDENTIFIED so only DBAs can enable it. Within a session, the user calls SET ROLE role_name IDENTIFIED BY password.

Best practices for Oracle RBAC

Create narrow, task-oriented roles. Grant only necessary privileges. Use WITH ADMIN OPTION sparingly.Review roles regularly and revoke unused ones.

What common mistakes should I avoid?

First, forgetting to grant privileges to the role—users get the role but no access. Second, failing to set the role as default—users must run SET ROLE manually each session.

.

Why How to Use RBAC in Oracle is important

How to Use RBAC in Oracle Example Usage


-- 1. Create role for read-only customer and order data
CREATE ROLE analyst_ro;

-- 2. Grant object privileges
GRANT SELECT ON Customers TO analyst_ro;
GRANT SELECT ON Orders    TO analyst_ro;

-- 3. Assign role to user and make it default
GRANT analyst_ro TO analyst_dev;
ALTER USER analyst_dev DEFAULT ROLE analyst_ro;

How to Use RBAC in Oracle Syntax


CREATE ROLE role_name [IDENTIFIED BY password | NOT IDENTIFIED];
GRANT system_privilege [, …] TO role_name [WITH ADMIN OPTION];
GRANT object_privileges ON schema.object TO role_name [WITH GRANT OPTION];
REVOKE privilege ON schema.object FROM role_name;
ALTER USER user_name DEFAULT ROLE { role_name | ALL | NONE };
SET ROLE role_name [IDENTIFIED BY password];

Common Mistakes

Frequently Asked Questions (FAQs)

Can one role grant privileges to another?

Yes. Grant the first role to the second with GRANT role_a TO role_b; to build role hierarchies.

How do I list privileges inside a role?

Query DBA_ROLE_PRIVS for roles and ROLE_TAB_PRIVS for object privileges granted to a role.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.