473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

Script to create readonly schema of existing schema.

debasisdas
8,127 Expert 4TB
The following script is used to create a read only schema of any existing schema in the same database. The readonly schema is granted only read permisions on the tables and views of the existing schema. No previliges on any other objects. The script can be customized as per requirment.


Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PROCEDURE CREATE_READONLY_SCHEMA (
  2.   i_owner IN VARCHAR2,
  3.   i_readonly IN VARCHAR2
  4.   )
  5. IS
  6.  
  7.   CURSOR cur_c1
  8.   IS
  9.   SELECT OBJECT_NAME, OBJECT_TYPE
  10.   FROM DBA_OBJECTS
  11.   WHERE OWNER = i_owner
  12.   AND OBJECT_TYPE IN ('TABLE', 'VIEW')
  13.   AND OBJECT_NAME NOT LIKE 'BIN$%' AND STATUS = 'VALID';
  14.  
  15. BEGIN
  16.   BEGIN
  17.   IF i_owner=i_readonly then
  18.   dbms_output.put_line('Please use a different name for the Readonly Schema');
  19.   exit;
  20.   else
  21.  
  22. --drop the readonly user if it already exists. This grants previliges on newly added tables and views in the original schema.
  23.     EXECUTE IMMEDIATE
  24.     'DROP USER '||i_readonly ||' CASCADE';
  25.   end if;
  26.   EXCEPTION
  27.     WHEN OTHERS
  28.     THEN
  29.       NULL;
  30.   END;
  31.   BEGIN
  32.     EXECUTE IMMEDIATE
  33.     'CREATE USER ' || i_readonly || ' IDENTIFIED BY ' || i_readonly || ' DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP2';
  34. --The tablespace part can be customized.
  35. --The password can also be customized or altered later on.
  36.     EXECUTE IMMEDIATE
  37.     'GRANT CONNECT TO ' || i_readonly;
  38.   EXCEPTION
  39.     WHEN OTHERS
  40.     THEN
  41. --add any exception handler if you want.
  42.       NULL;
  43.   END;
  44.  
  45.   FOR rec IN cur_c1
  46.   LOOP
  47.     BEGIN
  48.       EXECUTE IMMEDIATE
  49.       'GRANT SELECT ON ' || i_owner || '.' || rec.OBJECT_NAME || ' TO ' || i_readonly;
  50.  
  51.       EXECUTE IMMEDIATE
  52.       'CREATE OR REPLACE VIEW ' || i_readonly || '.' || rec.OBJECT_NAME || ' AS SELECT * FROM ' || i_owner || '.' || rec.OBJECT_NAME;
  53.     EXCEPTION
  54.       WHEN OTHERS
  55.       THEN
  56.         DBMS_OUTPUT.PUT_LINE('Refresh Attempt Failed for : ' || rec.Object_Name || ' (' || rec.Object_Type || ')');
  57.     END;
  58.   END LOOP;
  59. END CREATE_READONLY_SCHEMA;
Nov 21 '08 #1
0 8940

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: cmc | last post by:
I need some clarification to help me understand the DB2 strucure more. The questions are about "implicit schema" 1. This is a very interest concpet that DB2 let every user to create new schema...
5
by: devi | last post by:
hi, I am creating a simple bug tracker application (in Access db) and i created a hisotry table to log the bug history. The history table contains details like ProblemRecordNo (PRN),...
2
by: Anantha | last post by:
Dear All, One day our Windows 2000 Server OS crashed, so our NT admin has re-installed the OS on C: drive. Fortunately we kept our database file and installation in F: drive. When we...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
3
by: aventerprise | last post by:
<html> <head> <title></title> <script type="javascript" src="E:\Internet\positive_gearing.js"> function positve_gearing() { var price = form.price.value; var rates = form.rates.value;
1
by: anilkumar1980 | last post by:
Hi All, Here I need help to all of u, I am using ASP.NET 2.0 and Third party Infragistic Controls. I Have included master page in my page (<%@ Page Language="VB"...
1
by: gdev | last post by:
Having some trouble getting my head around setting access to specific schemas- here's my problem: I've created a specific schema that I only want certain users to control Problem: Even...
0
by: mvsguy | last post by:
I'm running a script from the PC Command Center to a z/OS DB2 at v8.1.5. In mid script, the schema changes, despite my setting it explicitly at the start of the script. Does anyone know what...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.