Oracle Articles, Oracle Tools, Oracle Tips, Database Articles and DBA Tips  

The Largest Online Resource for Oracle Articles, Oracle Tips, Oracle Scripts & Oracle Tools!!


Enter your Email:
 
Navigate at FreeMegaZone Home      Articles      Tools      Jobs      Games      Support      Submit Content      Advertise
Advertise at http://www.articles.freemegazone.com

Advertise at FreeMegaZone

Give tremendous boost to your business by advertising at FreeMegaZone. Contact webmaster@freemegazone.com

 

Rating: *****                                             Rate this article:    

 Author: John Memon

Page: 1 2

In prior releases of Oracle users could be granted SELECT privilege to make a table read-only. However the owner of the table had the read-write privileges and hence an owner could do updates and inserts on that table.

Oracle 11g database has made it possible to make a table read only for not only the database user but the owner of the table as well. You can convert a table from read/write state to read only state and vice-versa. 

Oracle 11g Read Only Tables - Oracle Articles - Database Articles - DBA Tips

Oracle 11g Read-Only Tables:

Below command can be used to make a table read only. 

ALTER TABLE table_name READ ONLY;

Below script creates a table, inserts a row and then sets the table to read-only.

CREATE TABLE READ_ONLY_TABLE (
id NUMBER
);

INSERT INTO READ_ONLY_TABLE VALUES (1);
ALTER TABLE READ_ONLY_TABLE READ ONLY;

The [DBA|ALL|USER]_TABLES views have a new column called READ_ONLY which can be used to see which tables are read only in the schema.

DML Statements for Read-Only Table:

Now if you try to run any query that affect the table data and SELECT ... FOR UPDATE queries result in an ORA-12081 error message.

Read Only Tables – Insert Query:

SQL> INSERT INTO READ_ONLY_TABLE VALUES (5);

INSERT INTO READ_ONLY_TABLE VALUES (5)
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."READ_ONLY_TABLE"

Read Only Tables – Update Query:

SQL> UPDATE READ_ONLY_TABLE SET id = 2;

UPDATE READ_ONLY_TABLE SET id = 2
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."READ_ONLY_TABLE"

Read Only Tables – Delete Query:

SQL> DELETE FROM READ_ONLY_TABLE;

DELETE FROM READ_ONLY_TABLE
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."READ_ONLY_TABLE"

Page: 1 2

 More Oracle Articles, Database Articles and DBA Tips
   Database Security: Step by step guideline
   Oracle Date Formats
   Automated Database management makes life easy!!
   Some Exciting Oracle Advisory Utilities you should not miss!!
   Performance Boost by improving Optimizer Statistics!


FreeMegaZone Jobs!!

 

 
HOME      ABOUT US      SUPPORT      SITE MAP      PRIVACY POLICY      TERMS OF USE      SUBMIT CONTENT      ADVERTISE
Copyright © 2007 - 2010 Oriole Intellect Inc. All rights reserved.

The name Oracle is a trademark of Oracle Corporation. Any other names used on this website may be trademarks of their respective owners