Oracle SET ROLE

Last updated on May 31 2022
Sankalp Joshi

Table of Contents

Oracle SET ROLE

Introduction to Oracle SET ROLE statement

The SET ROLE statement allows you to enable and disable roles for your current session.

Here is that the basic syntax of the SET ROLE statement:

SET ROLE role;

In this syntax, you only got to specify the role that was previously granted to your account.

If the role requires a password, you employ the subsequent syntax:

SET ROLE role IDENTIFIED BY password;

It is possible to enable multiple roles directly just like the following statement:

SET ROLE role1, role2, …;

Or

 

SET ROLE

role1,

role2 IDENTIFIED BY password,

…;

Note that you simply cannot enable quite 148 user-defined roles at just one occasion .

To enable all roles previously granted to your account, you employ the subsequent syntax:

SET ROLE ALL;

Note the SET ROLE ALL statement won’t enable the roles with passwords, which are granted on to you.

If you would like to enable all roles apart from a task , you employ this syntax:

SET ROLE ALL EXCEPT except_role;

The except_role role must be previously granted on to you. It can’t be granted indirectly to you thru other roles.

To disable all roles including the DEFAULT role, you employ the subsequent statement:

SET ROLE NONE;

The session_roles data dictionary view provides the currently enabled roles in your current session:

SELECT * FROM session_roles;

Oracle SET ROLE statement examples

First, create a user named scott and grant him the CREATE SESSION privilege in order that he can log within the database:

CREATE USER scott IDENTIFIED BY abcd1234;

 

GRANT CREATE SESSION TO scott;

Second, create two roles called warehouse_manager and warehouse_staff:

 

CREATE ROLE warehouse_staff;

CREATE ROLE warehouse_manager IDENTIFIED BY xyz123;

Third, grant object privileges on inventories table to the warehouse_staff role:

GRANT SELECT, INSERT, UPDATE, DELETE

ON inventories

TO warehouse_staff;

Fourth, grant object privileges on warehouses table to the warehouse_manager role:

GRANT SELECT, INSERT, UPDATE, DELETE

ON warehouses

TO warehouse_manager;

Fifth, grant privileges of the warehouse_staff role to warehouse_manager role:

GRANT warehouse_staff to warehouse_manager;

Sixth, grant the role warehouse_manager to scott:

GRANT warehouse_manager TO scott;

Seventh, log in to the database as scott and enable the warehouse_manager role:

SET ROLE warehouse_manager IDENTIFIED BY xyz123;

Eighth, view the present roles of scott:

SELECT * FROM session_roles;

Here is that the output:

ROLE

——————

WAREHOUSE_STAFF

WAREHOUSE_MANAGER

The user scott has two roles: warehouse_manager which was directly granted and warehouse_staff that was indirectly granted via the warehouse_manager role.

Ninth, to disable all roles of scott, you employ this statement:

SET ROLE NONE;

So, this brings us to the end of blog. This Tecklearn ‘Oracle SET ROLE’ blog helps you with commonly asked questions if you are looking out for a job in Oracle DB. If you wish to learn Oracle DB and build a career in Database domain, then check out our interactive, Oracle 12c DBA Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/oracle-12c-dba-course/

Oracle 12c DBA Course Training

About the Course

Oracle Database Administration training will help you master the Oracle DBA. As part of the training, you will master the Oracle Database architecture, the database processes, memory structures, schema objects, security, data recovery and backup through hands-on projects and case studies. Oracle DBA Training helps students gain the skills and knowledge required to install, configure, and administer Oracle databases. Besides, this training also develops the full skill set required to become a successful Oracle Database Administrator.

Why Should you take Oracle DBA Training?

  • The Average salary of an Oracle DBA is $108,837 per annum – GlassDoor.com
  • According to Gartner, Oracle is the market leader in the Relational Database with 48.35% market share globally.
  • IBM, TCS, Tech Mahindra, Oracle, Wipro & other MNCs worldwide use Pl-SQL for their database deployments.

What you will Learn in this Course?

Introduction to Oracle Database

  • What is the Oracle Database
  • Pre-requisites for oracle database
  • Oracle database 12c installation
  • Multi-tenant architecture

Exploring the Oracle 12c Database Architecture

  • Explain the Memory Structures
  • Describe the Process Structures
  • Overview of Storage Structures

Preparing the Database Environment

  • Identify the tools for Administering an Oracle Database
  • Plan an Oracle Database Installation
  • Install the Oracle Software by using Oracle Universal Installer (OUI)
  • Create a Database by using the Database Configuration Assistant (DBCA)

Managing the Oracle Instance

  • Setting database initialization parameters
  • Describe the stages of database startup and shutdown

Database Storage Structures and Schema Objects

  • Managing Database Storage Structures
  • Overview of table space and data files
  • Overview of Primary Components
  • Identify the importance of checkpoints, redo log files, and archived log files
  • Configure ARHIVELOG mode

Database Startup & User Requests and Oracle Network Environment

  • Describe the stages of database startup and shutdown
  • Using alert log and trace files
  • Configure and Manage the Oracle Network
  • pFile and spFile
  • Tablespace Management
  • Storage and Relationship Structure

Oracle Backup & Recovery

  • Redo log File Management
  • Performing Database Recovery
  • Overview of Data Recovery Advisor
  • Use Data Recovery Advisor to Perform recovery (Control file, Redo log file and Data file)

Deep Dive into Oracle Recovery Manager (RMAN)

  • Using the RMAN Recovery Catalog
  • Identify situations that require RMAN recovery catalog
  • Create and configure a recovery catalog
  • Synchronize the recovery catalog
  • Create and Use RMAN stored scripts
  • Back up the recovery catalog
  • Create and use a virtual private catalog

Configuring Backup Specifications

  • Using RMAN to Create Backups
  • Create image file backups
  • Create a whole database backup
  • Enable fast incremental backup
  • Using RMAN to Perform Recovery
  • Perform complete recovery from a critical or noncritical data file loss using RMAN
  • Perform incomplete recovery using RMAN

Data Movement and Oracle Data Pump

  • Moving Data
  • Describe and use methods to use move data (Directory objects, SQL* Loader, External tables)
  • Explain the general architecture of Oracle Data Pump

Data Dictionary & Dynamic Performance Tables

  • Oracle Data Dictionary contains information related to database privileges
  • Data dictionary views
  • Media failure
  • Flashback CDB

Database Tuning

  • What is database tuning
  • How to tune the database
  • Tuning the data dictionary

 

 

0 responses on "Oracle SET ROLE"

Leave a Message

Your email address will not be published. Required fields are marked *