Skip to main content

Read-Only Tables in Oracle Database 11g


Read-Only Tables in Oracle Database 11g Release 1


In previous Oracle releases, tables could be made to appear read-only to other users by only granting the SELECT object privilege to them, but the tables remained read-write for the owner. Oracle 11g allows tables to be marked as read-only using the ALTER TABLE command.
ALTER TABLE table_name READ ONLY;
ALTER TABLE table_name READ WRITE;
The following script creates a table, inserts a row, then sets the table to read-only.
CREATE TABLE ro_tab (
  id  NUMBER
);


INSERT INTO ro_tab VALUES (1);
ALTER TABLE ro_tab READ ONLY;
Any DML statements that affect the table data and SELECT ... FOR UPDATE queries result in an ORA-12081 error message.
SQL> INSERT INTO ro_tab VALUES (2);
INSERT INTO ro_tab VALUES (2)
            *
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."RO_TAB"




SQL> UPDATE ro_tab SET id = 2;
UPDATE ro_tab SET id = 2
       *
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."RO_TAB"




SQL> DELETE FROM ro_tab;
DELETE FROM ro_tab
            *
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."RO_TAB"
DDL statements that affect the table data are also restricted.
SQL> TRUNCATE TABLE ro_tab;
TRUNCATE TABLE ro_tab
               *
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."RO_TAB"




SQL> ALTER TABLE ro_tab ADD (description VARCHAR2(50));
ALTER TABLE ro_tab ADD (description VARCHAR2(50))
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."RO_TAB"
Operations on indexes associated with the table are unaffected by the read-only state. DML and DDL operations return to normal once the table is switched back to read-write mode.
SQL> ALTER TABLE ro_tab READ WRITE;


Table altered.


SQL> DELETE FROM ro_tab;


1 row deleted.


SQL>
The read-only status of tables is displayed in the READ_ONLY column of the [DBA|ALL|USER]_TABLES views.

Comments

Popular posts from this blog

ORA-65139: Mismatch between XML metadata file and data file

Error: CDB$ROOT@EBTUPRDC> CREATE PLUGGABLE DATABASE EBTUSPRDPDB1 using '/home/oracle/EBTUSPRDC.xml' nocopy tempfile reuse; CREATE PLUGGABLE DATABASE EBTUSPRDPDB1 using '/home/oracle/EBTUSPRDC.xml' nocopy tempfile reuse * ERROR at line 1: ORA-65139: Mismatch between XML metadata file and data file /u05/odb/ORADATA_1/EBTUSPRDC/datafile/system.1531.807800993 for value of fcpsb (2230502002 in the plug XML file, 2230505492 in the data file) Fix: Don't open Non-CDB database until we complete pdb creation other wise we will get above error. Shutdown immediate; startup mount; alter database open read only; create xml file. shutdown immediate; Connect to CDB and Create Pluggable database .

Useful OEM Queries to get Target details from OEM Repository

List Targets with TNS Listener ports configured : SELECT mgmt$target.host_name , mgmt$target.target_name , mgmt$target.target_type , mgmt$target_properties.property_name , mgmt$target_properties.property_value FROM mgmt$target , mgmt$target_properties WHERE ( mgmt$target.target_name = mgmt$target_properties.target_name ) AND ( mgmt$target.target_type = mgmt$target_properties.target_type ) and ( mgmt$target.target_type = 'oracle_listener' ) and ( mgmt$target_properties.property_name = 'Port' ); Devora02       LISTENER_ora02                       oracle_listener Port 1529 Devora01       LISTENER_ora01                       oracle_listener Port 1529 Devora04       LISTENE...

TFA-00002 : Oracle Trace File Analyzer (TFA) is not running

TFA Failed to start listening for commands on one of the Rac Node : As a root user /etc/init.d/init.tfa  start Starting TFA.. start: Job is already running: oracle-tfa Waiting up to 100 seconds for TFA to be started.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Successfully started TFA Process.. . . . . . TFA-00002 : Oracle Trace File Analyzer (TFA) is not running TFA Failed to start listening for commands Solution : run synctfanodes.sh  if you have root password . if no root password copy below files to TFA Failed node and try to restart TFA .. Please check whether these 4 files exist on all nodes are similar. TFA_HOME/server.jks TFA_HOME/client.jks TFA_HOME/internal/ssl.properties   TFA_HOME/internal/ portmapping.txt If not similar just copy these files to TFA Failing node and try TFA Restart ..It Worked for me .   [root@host01]# ./tfactl  -v "debug" start Starting TFA...