Kayshav.com
About Developer Oracle 11g Technology Information Sitemap

Oracle 11g Table - Read Only/Read Write
-- In Oracle versions earlier than 11g, the table was setup as READ ONLY 
-- by granting SELECT access for the table to users other than the table
-- owner.  The OS READ ONLY privilege had to be used on underlying 
-- tablespace to make the table read only for the owner.  In 11g, even 
-- owner can set the table to be READ ONLY to prevent accidental DML
-- and switch over to READ WRITE when needed.

-- Create Table (for simplicity PK/FK not setup)

CREATE TABLE edw_sales_fact
(division_id     NUMBER,
 invoice_id      NUMBER,
 quantity        NUMBER,
 sales_amt       NUMBER,
 invoice_date    DATE,
 created_date    DATE DEFAULT SYSDATE NOT NULL
);

Create Table

-- Load Data

INSERT INTO edw_sales_fact
(division_id, invoice_id, quantity,
 sales_amt, invoice_date)
SELECT 100, 9001, 255.5, 25005, '15-JAN-2011' FROM DUAL;

INSERT INTO edw_sales_fact
(division_id, invoice_id, quantity,
 sales_amt, invoice_date)
SELECT 100, 9002, 171, 15005, '11-FEB-2011'  FROM DUAL;

COMMIT;

Load Data

-- Alter table and set it to READ ONLY
-- Load data script fails (ORA-12081 error) even for the user as is setup
-- to be READ ONLY

ALTER TABLE edw_sales_fact READ ONLY;

INSERT INTO edw_sales_fact
(division_id, invoice_id, quantity,
 sales_amt, invoice_date)
SELECT 100, 9003, 217, 27120, '11-MAR-2011'
FROM DUAL;

Execute Load fails when Table is in READ ONLY mode

-- Alter table and set it to READ WRITE
-- Load data executes inserting a row

ALTER TABLE edw_sales_fact READ WRITE;

INSERT INTO edw_sales_fact
(division_id, invoice_id, quantity,
 sales_amt, invoice_date)
SELECT 100, 9003, 217, 27120, '11-MAR-2011'
FROM DUAL;

COMMIT;

Load Data succeeds


Oracle 11gXEr2 - Index

Oracle registered trademark of Oracle Corporation.

Last Revised On: September 21, 2014

  24044