Tuesday, February 5, 2013

How to Create a Read Only Schema in Oracle R12.

Method :1

SQL> CREATE USER APPSREAD IDENTIFIED BY APPSREAD;  
User created.
SQL>

SQL> GRANT CONNECT, RESOURCE,CREATE SYNONYM TO APPSREAD;
Grant succeeded.  
SQL>

Generate a Script for creating database objects of Application User ‘APPS’

set echo off set
pagesize 0
set linesize 300
spool cr8synonyms.sql
select 'create synonym ' || OBJECT_NAME || ' for '|| OWNER ||'.' ||OBJECT_NAME || ';' from all_objects where OWNER in ('APPS') and
OBJECT_NAME not like '%/%' and OBJECT_TYPE in ('TABLE','VIEW','SYNONYM');  
spool off

Generate a script for selecting database objects of Application User ‘APPS’

spool GrantSelect.sql  
select 'grant select on '|| OWNER ||'.' ||OBJECT_NAME || ' to APPSREAD;' from all_objects  where OWNER not in ('SYS','SYSTEM') and OBJECT_NAME not like '%/%' and OBJECT_TYPE in ('TABLE','VIEW','SYNONYM');  
spool off

Connect to sqlplus  as sysdaba and execute the following script

SQL> @GrantSelect.sql
SQL> @cr8synonyms.sql

Connect to Read only schema User and check the objects.

SQL> conn oracle/oracle Connected.
SQL> select count(*) from tab;    
COUNT(*) ----------      15515  
SQL>

3 comments:

  1. brillant piece of information, I had come to know about your web-page from my friend hardkik, chennai,i have read atleast 9 posts of yours by now, and let me tell you, your webpage gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanx a million once again, Regards, Synonyms



    ReplyDelete
  2. too good piece of information, I had come to know about your site from my friend sajid, bangalore,i have read atleast 11 posts of yours by now, and let me tell you, your web-page gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new post, once again hats off to you! Thanks a lot once again, Regards, Synonyms In Oracle



    ReplyDelete
  3. Dear,

    It's good information but I have notice that while creating the script for grant select.. we need to exclude some other schema too (i.e. CTXSYS)

    Please correct me if I am wrong.

    Jignesh

    ReplyDelete