Read-Only Tables in Oracle Database 11g Release 1
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;
1.The following script creates a table, inserts a row, then sets the table to read-only.
TEST@ sms> create table t1( id number,name varchar2(20));
TEST@ sms> insert into t1 values(1,'aa');
TEST@ sms> insert into t1 values(2,'bb');
TEST@ sms> alter table t1 read only;
TEST@ sms> select TABLE_NAME,READ_ONLY from user_tables where table_name='T1';
TABLE_NAME READ_ONLY
-------------------- ------------------------------
T1 YES
2.Any DML statements that affect the table data and SELECT ... FOR UPDATE queries result in an ORA-12081 error message.
TEST@ sms> insert into t1 values(3,'cc');
insert into t1 values(3,'cc')
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
TEST@ sms> update t1 set id=10 where id=1;
update t1 set id=10 where id=1
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
TEST@ sms> delete t1 where id=1;
delete t1 where id=1
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
TEST@ sms> truncate table t1;
truncate table t1
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
3.DDL statements that affect the table data are also restricted.
TEST@ sms> drop table t1;
Table dropped.
TEST@ sms> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
T1 BIN$BY3lIab8LA7gUwEAAH8WYQ==$0 TABLE 2014-10-17:00:48:02
TEST@ sms> flashback table t1 to before drop;
Flashback complete
TEST@ sms> select TABLE_NAME,READ_ONLY from user_tables where table_name='T1';
TABLE_NAME READ_ONLY
-------------------- ------------------------------
T1 YES
4. 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.
TEST@ sms> alter table t1 read write;
Table altered.
TEST@ sms> insert into t1 values(3,'ccc');
1 row created.
5. The read-only status of tables is displayed in the READ_ONLY column of the [DBA|ALL|USER]_TABLES views.
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;
1.The following script creates a table, inserts a row, then sets the table to read-only.
TEST@ sms> create table t1( id number,name varchar2(20));
TEST@ sms> insert into t1 values(1,'aa');
TEST@ sms> insert into t1 values(2,'bb');
TEST@ sms> alter table t1 read only;
TEST@ sms> select TABLE_NAME,READ_ONLY from user_tables where table_name='T1';
TABLE_NAME READ_ONLY
-------------------- ------------------------------
T1 YES
2.Any DML statements that affect the table data and SELECT ... FOR UPDATE queries result in an ORA-12081 error message.
TEST@ sms> insert into t1 values(3,'cc');
insert into t1 values(3,'cc')
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
TEST@ sms> update t1 set id=10 where id=1;
update t1 set id=10 where id=1
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
TEST@ sms> delete t1 where id=1;
delete t1 where id=1
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
TEST@ sms> truncate table t1;
truncate table t1
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "TEST"."T1"
3.DDL statements that affect the table data are also restricted.
TEST@ sms> drop table t1;
Table dropped.
TEST@ sms> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
T1 BIN$BY3lIab8LA7gUwEAAH8WYQ==$0 TABLE 2014-10-17:00:48:02
TEST@ sms> flashback table t1 to before drop;
Flashback complete
TEST@ sms> select TABLE_NAME,READ_ONLY from user_tables where table_name='T1';
TABLE_NAME READ_ONLY
-------------------- ------------------------------
T1 YES
4. 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.
TEST@ sms> alter table t1 read write;
Table altered.
TEST@ sms> insert into t1 values(3,'ccc');
1 row created.
5. The read-only status of tables is displayed in the READ_ONLY column of the [DBA|ALL|USER]_TABLES views.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27036311/viewspace-1301833/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Automatic Diagnostic Repository (ADR) in Oracle Database 11g Release 1 (ADRCI)OracleDatabase
- 1 Oracle Database Release 20c New FeaturesOracleDatabase
- [20181112]Private Temporary Tables Oracle Database 18C.txtOracleDatabase
- Oracle 11g 新特性:只讀表(Read-only)Oracle
- Oracle 19c Concepts(00):Changes in This Release for Oracle Database ConceptsOracleDatabase
- Oracle:ORA-01219:database not open:queries allowed on fixed tables/views onlyOracleDatabaseView
- 3.2.3 Opening a Database in Read-Only ModeDatabase
- Oracle TablesOracle
- 1 Oracle Database 19c 新特性OracleDatabase
- 【Oracle】Windows安裝oracle11gR1 database 11.1.0.6OracleWindowsDatabase
- Oracle 11g 052題庫解析1Oracle
- 【OCP最新題庫解析(052)--題9】You want to install Oracle 11g databaseOracleDatabase
- ORACLE database vaultOracleDatabase
- Oracle clone databaseOracleDatabase
- Oracle Database Cloud - Database as a Service Quick StartOracleDatabaseCloudUI
- [轉帖]Release Schedule of Current Database Releases (Doc ID 742060.1)Database
- ORACLE-1Z0-060題庫(Upgrade to Oracle Database 12c)OracleDatabase
- Oracle Database Scheduler整理OracleDatabase
- Oracle Physical Database LimitsOracleDatabaseMIT
- Oracle Database 12cR2/R1中的更改OracleDatabase
- Oracle 19c Concepts(02):Tables and Table ClustersOracle
- Oracle 12.2 使用Database Link優化Standby Database WorkloadOracleDatabase優化
- Oracle之11g DataGuardOracle
- Oracle 19c Concepts(01):Introduction to Oracle DatabaseOracleDatabase
- Oracle 19c Concepts(13):Oracle Database InstanceOracleDatabase
- Oracle OCP(35):Database 安裝OracleDatabase
- oracle 10g flashback databaseOracle 10gDatabase
- Oracle DG Standby Database型別OracleDatabase型別
- Oracle DG建立Physical Standby DatabaseOracleDatabase
- Oracle DG建立Logical Standby DatabaseOracleDatabase
- Oracle 11G 安裝文件Oracle
- benchmark 壓測Oracle 11gOracle
- sysbench壓測Oracle 11gOracle
- oracle 12c release 2 安裝Oracle
- Oracle 11G RAC叢集安裝(1)——安裝前的準備Oracle
- Oracle 12C Database File Mapping for Oracle ASM FilesOracleDatabaseAPPASM
- TiDB 2.0 RC1 ReleaseTiDB
- Oracle 19c Concepts(03):Indexes and Index-Organized TablesOracleIndexZed
- Oracle OCP(38):Database 物理結構OracleDatabase