Oracle Tutorial

  • Home
  • Start Here
  • Basics
  • Advanced
    • Oracle View
    • Oracle Index
    • Oracle Synonym
    • Oracle Sequence
    • Oracle Administration
  • PL/SQL
  • Functions
    • Aggregate Functions
    • Analytic Functions
    • Comparison Functions
    • Date Functions
    • String Functions
  • API
    • Python Oracle
Home / Oracle Database Administration / How To Grant SELECT Object Privilege On One or More Tables to a User

How To Grant SELECT Object Privilege On One or More Tables to a User

Summary: in this tutorial, you will learn how to use the Oracle GRANT statement to grant SELECT object privilege on one or more tables to a user.

Grant SELECT on a table to a user

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

GRANT SELECT ON table_name TO {user | role};

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

First, create a new 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 the output:

COUNT(*) ---------- 319

Grant SELECT on all tables in a schema to a user

Sometimes, you want to grant SELECT on all tables which belong to a schema or user to another user. Unfortunately, Oracle doesn’t directly support this using a single SQL statement.

To work around this, you can 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.

In this tutorial, you have learned how to grant the SELECT object privilege on one or more tables to a user.

  • Was this tutorial helpful?
  • YesNo
Previous How to Grant All Privileges to a User in Oracle
Next How To Unlock a User in Oracle

Getting Started

  • What Is Oracle Database
  • Install Oracle Database Server
  • Download Oracle Sample Database
  • Create Oracle Sample Database
  • Connect To Oracle Database Server

Oracle Data Manipulation

  • SELECT
  • Oracle DUAL Table
  • ORDER BY
  • SELECT DISTINCT
  • WHERE
  • Table & Column Aliases
  • AND
  • OR
  • FETCH
  • BETWEEN
  • IN
  • LIKE
  • IS NULL
  • Joins
  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN
  • CROSS JOIN
  • Self Join
  • GROUP BY
  • HAVING
  • UNION
  • INTERSECT
  • MINUS
  • GROUPING SETS
  • CUBE
  • ROLLUP
  • PIVOT
  • UNPIVOT
  • INSERT
  • INSERT INTO SELECT
  • INSERT ALL
  • UPDATE
  • DELETE
  • MERGE
  • Subquery
  • Correlated Subquery
  • EXISTS
  • NOT EXISTS
  • ANY
  • ALL

Oracle Data Types

  • Oracle Data Types
  • NUMBER
  • FLOAT
  • BINARY_FLOAT
  • CHAR
  • NCHAR
  • VARCHAR2
  • NVARCHAR2
  • DATE
  • INTERVAL
  • TIMESTAMP
  • TIMESTAMP WITH TIME ZONE

Oracle Data Definition

  • CREATE TABLE
  • Identity Column
  • ALTER TABLE
  • ALTER TABLE ADD Column
  • ALTER TABLE MODIFY Column
  • Drop Columns
  • DROP TABLE
  • TRUNCATE TABLE
  • RENAME Table
  • Oracle Virtual Column

Oracle Constraints

  • PRIMARY KEY
  • FOREIGN KEY
  • UNIQUE
  • CHECK
  • NOT NULL

Oracle Views

  • CREATE VIEW
  • DROP VIEW
  • Updatable Views
  • Inline Views
  • WITH CHECK OPTION

About Oracle Tutorial

OracleTututorial.com website provides Developers and Database Administrators with the updated Oracle tutorials, scripts, and tips.

Search

Recent Tutorials

  • Oracle Implicit Statement Results
  • Calling PL/SQL Stored Functions in Python
  • Calling PL/SQL Procedures in Python
  • Managing Transaction in Python
  • Deleting Data From Oracle Database in Python

Site Links

  • Oracle Books
  • About
  • Contact
  • Privacy Policy
  • Terms of Use

Copyright © 2021 Oracle Tutorial. All Rights Reserved.