首页 > 数据库 > Oracle > 11g_Readonly_Table
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/ ,如需转载,请注明出处,否则将追究法律责任。