About Me.

My self Adinarayana working as Implementation Application DBA with advanced technologies like RAC/PCP,OID/SSO,DMZ,Exadata and Fusion Middleware i.e Demantra,Application Server,SOA,FMW,BPEL and UPK. Created this blog to share the useful information related to DBA and Application DBA Your comments and suggestions are most welcome. Disclaimer: Please note all the views and opinions expressed in this site are my own. It's not recommend to use the fixes/suggestions provided in this site directly in production instance, please test them before implementing.

Monday, July 22, 2013

Creating an Apps User like with only Select option

How to create to Oracle DB User which is like APPS but has only SELECT privileges (this user should not have to use schema name.objectname and all SELECT qeries run from APPS user should work from this DB User as well)

a.       Create a user using
Create user ‘username’ identified by ‘password’;

b.      Then execute the following command in the sql prompt as the sys user,

spool create_grants.sql
set echo off
set pagesize 0
set linesize 300
set feedback off
SELECT 'Grant select on APPS.'||object_name||' to A;' FROM user_objects WHERE object_type IN ('TABLE','VIEW');
spool off;
exit;

c.       Executing the script  would create a sql file name create_grants.sql that has all the ‘SELECT priveleges’ of all the objects that the APPS user has access to..
d.      Finally run the create_grants.sql script.

Or


->run the below commands :-

BEGIN

   FOR R IN (SELECT owner, table_name FROM all_tables WHERE owner='APPS') LOOP

      EXECUTE IMMEDIATE 'grant select on '||R.owner||'.'||R.table_name||' to A ';
   END LOOP;

END;
/


BEGIN
   FOR R IN (SELECT owner, view_name FROM all_views  WHERE owner='APPS') LOOP

      EXECUTE IMMEDIATE 'grant select on '||R.owner||'.'||R.view_name||' to B ';
   END LOOP;

END;

No comments:

Post a Comment