• Home
  • Databases
  • How to Grant SELECT Object Privilege on One or More Tables to a User and Unlock a User in Oracle

How to Grant SELECT Object Privilege on One or More Tables to a User and Unlock a User in Oracle

Last updated on May 31 2022
Sankalp Joshi

Table of Contents

How to Grant SELECT Object Privilege on One or More Tables to a User and Unlock a User in Oracle

Grant SELECT on a table to a user

To grant the SELECT object privilege on a table to a user or role, you employ the subsequent statement:

GRANT SELECT ON table_name TO {user | role};

The following example illustrates the way to grant the SELECT object privilege on a table to a user.

First, create a replacement user called DW and grant the CREATE SESSION to the user:

CREATE USER dw IDENTIFIED BY abcd1234;

 

GRANT CREATE SESSION TO dw;

Second, grant the SELECT object privilege on the ot.customers table to the dw user:

GRANT SELECT ON customers TO dw;

Finally, use the dw user to log in to the Oracle Database and query data from the ot.customers table:

SELECT COUNT(*)

FROM ot.customers;

Here is that the output:

COUNT(*)

———-

319

Grant SELECT on all tables during a schema to a user

Sometimes, you would like to grant SELECT on all tables which belong to a schema or user to a different user. Unfortunately, Oracle doesn’t directly support this employing a single SQL statement.

To work around this, you’ll select all table names of a user (or a schema) and grant the SELECT object privilege on each table to a grantee.

The following stored procedure illustrates the idea:

CREATE PROCEDURE grant_select(

username VARCHAR2,

grantee VARCHAR2)

AS

BEGIN

FOR r IN (

SELECT owner, table_name

FROM all_tables

WHERE owner = username

)

LOOP

EXECUTE IMMEDIATE

‘GRANT SELECT ON ‘||r.owner||’.’||r.table_name||’ to ‘ || grantee;

END LOOP;

END;

This example grants the SELECT object privileges of all tables that belong to the user OT to the user DW:

EXEC grant_select(‘OT’,’DW’);

When you use the user DW to login to the Oracle Database, the user DW should have the SELECT object privilege on all tables of the OT‘s schema.

To unlock a user in Oracle, you follow these steps:

  • First, log in to the Oracle Database as a SYS user.
  • Then, use ALTER USER statement to unlock the user as follows:

ALTER USER username IDENTIFIED BY password ACCOUNT UNLOCK;

 

Note that if you unlock an account without resetting the password, then the password remains expired, therefore, the IDENTIFIED BY password clause is important . the primary time the user logs in to the Oracle Database, he must change his password.

Let’s see an example of unlock a user.

Suppose user alice is locked. When alice logs in, she is going to see the subsequent message:

Enter user-name: alice@pdborcl

Enter password:

ERROR:

ORA-28000: the account is locked

To unlock the user alice, you employ these steps:

First, log in to the Oracle Database using theot user:

Enter user-name: ot@orclpdb

Enter password:

Then, use the ALTER USER statement to unlock user alice:

ALTER USER alice IDENTIFIED BY abcd1234 ACCOUNT UNLOCK;

Note that abcd1234 is that the new password that alice will use to log within the Oracle Database.

Now the user alice should be ready to log within the database with the new password.

So, this brings us to the end of blog. This Tecklearn ‘How to Grant SELECT Object Privilege on One or More Tables to a User and Unlock a User in Oracle’ 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 "How to Grant SELECT Object Privilege on One or More Tables to a User and Unlock a User in Oracle"

Leave a Message

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