Oracle 11g 新特性 -- 唯讀表(read-only table)說明

來源:互聯網
上載者:User

一.Read only table說明

在Oracle 11g之前,如果我們想要對一個表設定為唯讀,可以通過授予某些使用者select 許可權。 但是對於表的所有者來說,還是讀寫的。

在Oracle 11g中,我們可以直接對錶的讀寫權限進行設定:

ALTER TABLE table_name READ ONLY;

ALTER TABLE table_name READ WRITE;

二.樣本
 

--建立表

SQL> create table dave as select * fromdba_objects;

 

Table created.

 

--設定為唯讀:

SQL> alter table dave read only;

Table altered.

 

--查看錶狀態:

SQL> select table_name,status,read_onlyfrom dba_tables where table_name='DAVE';

 

TABLE_NAME                    STATUS  REA

------------------------------ -------- ---

DAVE                          VALID    YES

--這裡顯示是唯讀。

 

--對Dave表進行DML操作:

SQL> insert into dave select * fromdave;

insert into dave select * from dave

          *

ERROR at line 1:

ORA-12081: update operation not allowed ontable "SYS"."DAVE"

 

SQL> update dave set object_id=88;

update dave set object_id=88

      *

ERROR at line 1:

ORA-12081: update operation not allowed ontable "SYS"."DAVE"

 

 

SQL> delete from dave;

delete from dave

          *

ERROR at line 1:

ORA-12081: update operation not allowed ontable "SYS"."DAVE"

 

SQL> truncate table dave;

truncate table dave

              *

ERROR at line 1:

ORA-12081: update operation not allowed ontable "SYS"."DAVE"

 

 

SQL> alter table dave add(namevarchar(20));

alter table dave add(name varchar(20))

*

ERROR at line 1:

ORA-12081: update operation not allowed ontable "SYS"."DAVE"

 

 

--雖然表示唯讀,但是我們對錶進行與索引相關的操作,因為索引修改的是資料字典,和表不相關。

SQL> create index idx_id on dave(object_id);

 

Index created.

 

SQL> drop index idx_id;

 

Index dropped.

 

--將表改成讀寫:

SQL> altertable dave read write;

 

Table altered.

 

SQL> droptable dave;

 

Table dropped.

相關閱讀:Oracle 11g 的新特性 —— 唯讀表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.