ITPub博客

首页 > 数据库 > Oracle > 11g_Readonly_Table

11g_Readonly_Table

原创 Oracle 作者:zhyuh 时间:2009-09-24 14:16:52 0 删除 编辑
如果表能直接改成只读,那要保证数据不被修改的时候,就不用建只读视图,或者只读表空间了。[@more@]

SQL> select * from trans;

TRANS_ID CUST_NAME TRANS_DT TRANS_AMT STORE_ID ODD_
---------- -------------------- --------- ---------- ---------- ----
101 NLVULXSEUEGDDYEMJCSQ 06-JAN-08 28429555.7 23 ODD
102 WFIZTGOYWVDTQQHHODAL 31-JUL-08 88919063.1 19 ODD
110 cust_110 10-NOV-08 3543.12 23 ODD


==把表改成只读。
SQL> alter table trans read only;

Table altered.

SQL> select table_name,read_only from user_tables;

TABLE_NAME READ_ONLY
------------------------------ ----------
SALGRADE NO
BONUS NO
EMP NO
DEPT NO
TRANS YES

SQL> delete from trans where trans_id=102;
delete from trans where trans_id=102
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "SCOTT"."TRANS"


SQL> update trans set cust_name='CUST_102' where trans_id=102;
update trans set cust_name='CUST_102' where trans_id=102
*
ERROR at line 1:
ORA-12081: update operation not allowed on table "SCOTT"."TRANS"


==把表改回可读写。
SQL> alter table trans read write;

Table altered.

SQL> update trans set cust_name='CUST_102' where trans_id=102;

1 row updated.

SQL> delete from trans where trans_id=102;

1 row deleted.

SQL> commit;

Commit complete.

SQL> select * from trans;

TRANS_ID CUST_NAME TRANS_DT TRANS_AMT STORE_ID ODD_
---------- -------------------- --------- ---------- ---------- ----
101 NLVULXSEUEGDDYEMJCSQ 06-JAN-08 28429555.7 23 ODD
110 cust_110 10-NOV-08 3543.12 23 ODD


这种小功能,早N个版本前就该出来了。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/207/viewspace-1027308/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 11g_Calibrating_IO
下一篇: 11g_Table_Compression
请登录后发表评论 登录
全部评论
  • 博文量
    233
  • 访问量
    2061897