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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Partitioning Enhancements in Oracle Database 11g Release 1OracleDatabase
- 1 Oracle Database 11g Release 2 (11.2.0.4) New FeaturesOracleDatabase
- Oracle Database 11g Release 2 RAC On LinuxOracleDatabaseLinux
- Automatic Diagnostic Repository (ADR) in Oracle Database 11g Release 1 (ADRCI)OracleDatabase
- APPEND_VALUES Hint in Oracle Database 11g Release 2APPOracleDatabase
- Oracle® Database Error Messages 11g Release 2 (11.2)OracleDatabaseError
- Using Oracle Database 11g Release 2 Result Cache in an Oracle RAC EnvironmentOracleDatabase
- 1 Oracle Database Release 20c New FeaturesOracleDatabase
- Oracle Database 11g Release 2 RAC On Linux Using VMware Server 2OracleDatabaseLinuxServer
- Oracle 11g Release 1 (11.1) Data Pump 技術Oracle
- 在Centos 6.5上安裝Oracle Database 11g Release 2 (11.2.0.4.0) RACCentOSOracleDatabase
- Identifying Your Oracle Database Software Release (21)IDEOracleDatabase
- Oracle 11G Duplicate DatabaseOracleDatabase
- Oracle 11g 新特性:只讀表(Read-only)Oracle
- Major Database Release Number (22)Database
- Transparent Data Encryption (TDE) in Oracle 10g Database Release 2Oracle 10gDatabase
- 3.2.3 Opening a Database in Read-Only ModeDatabase
- Oracle Database 11g Launch WebcastOracleDatabaseWebAST
- Oracle Appliactions 11i concepts(四) - Database Features and Release 11i(1)OracleAPPDatabase
- [轉]How to release space from databaseDatabase
- Open a Database in Read-Only Mode (301)Database
- Oracle TablesOracle
- Oracle 11g Database Replay 實驗OracleDatabase
- Oracle 11g Rman Active database duplicateOracleDatabase
- Oracle Database 11g索引技術OracleDatabase索引
- Cursor Sharing in Oracle Database 11gOracleDatabase
- [Oracle] oracle 11g database install(linux)OracleDatabaseLinux
- oracle 11g Oracle Database Vault 的配置方法OracleDatabase
- Oracle 19c Concepts(00):Changes in This Release for Oracle Database ConceptsOracleDatabase
- Database 11g Release 2 Certification Highlights [ID 1065024.1]Database
- Types of Oracle Database Users : Database Administrators (1)OracleDatabase
- Oracle 11g Database靜默安裝OracleDatabase
- Oracle Externale TablesOracle
- Oracle - Tables/IndexesOracleIndex
- Oracle X$TablesOracle
- Oracle X$ TablesOracle
- Oracle Partitioned TablesOracle
- Reboot-less node fencing in Oracle Clusterware 11g Release 2bootOracle