Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

Read-only user Creation in Oracle

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Read-only user Creation in Oracle
  • User AvatarAshiwini
  • 26 Jul, 2024
  • 0 Comments
  • 2 Mins Read

Read-only user Creation in Oracle

Sometimes the DBA requires  to create the read-only user for a particular schemas.While creating the user,one should always keep in mind that the user should have minimum privileges.  There is no any direct command to create the read-only user in oracle.
Sometimes I find people grants  “read any table ”  privileges to create the read-only  user ,which is not correct.

Step 1 : Create User PDBUSER
SQL> create user PDBUSER identified by PDBUSER;
User created.
Step 2 : Grant session and create synonym privileges
SQL> grant create session ,create synonym to PDBUSER ;
Grant succeeded.
Step 3 : Make script to grant select privileges to PDBUSER

Created the script with the help of spool by selecting the tables of the HR schemas .

SQL> SPOOL select_privs.sql
SQL> select 'grant select on hr.'||table_name|| ' to PDBUSER;' from dba_tables where owner='HR';
SQL> select 'grant select on hr.'||view_name|| ' to PDBUSER;' from dba_views where owner='HR';
SQL> spool off

Now , we will check the spool “select _privs.sql” and prepare this as script for grant permission.

Step 4 : Run the script to grant the permission
SQL> @select_privs.sql

The script “select_privs.sql” script after modification is .

grant select on hr.REGIONS to PDBUSER; 
grant select on hr.LOCATIONS to PDBUSER; 
grant select on hr.DEPARTMENTS to PDBUSER; 
grant select on hr.JOBS to PDBUSER; 
grant select on hr.EMPLOYEES to PDBUSER; 
grant select on hr.JOB_HISTORY to PDBUSER; 
grant select on hr.COUNTRIES to PDBUSER; 
grant select on hr.EMP_DETAILS_VIEW to PDBUSER;
Step 5 : Create the synonym

Connect to “PDBUSER” schemas and create the synonym so that the “PDBUSER” user can access the “HR” schemas without any dot(.) like select * from employees instead of “select * from HR.employees” .Here again we use the above method.

SQL> conn PDBUSER/PDBUSER@orcl
SQL> SPOOL synonym_privs.sql
SQL> select 'create synonym '||view_name|| ' for HR.'||view_name||';' from all_views where owner='HR';
SQL> select 'create synonym '||table_name|| ' for HR.'||table_name||';' from all_tables where owner='HR';
SQL> spool off

Now we have the script to create the synonym

SQL>@synonym_privs.sql

Now we have successfully created a read-only user for a particular schemas.

Step 6 : Check the tables
SQL> select Count(*) from employees ;

COUNT(*)
----------
107

SQL> select Count(*) from hr.employees;

COUNT(*)
----------
107

SQL> show user
USER is "PDBUSER