12c 資料庫內歸檔

來源:互聯網
上載者:User

   Oracle 12c有一個新特性,能夠在資料庫內歸檔,將不常訪問的資料對應用隱藏起來,設定為inactive狀態。當然也可以在會話層級進行顯示。這是通過參數ROW ARCHIVAL VISIBILITY來實現的,該參數可以設定為兩個值,active或all。active為顯示活動的資料,all為顯示所有資料,包括inactive的資料。

   現舉例說明:

 SQL> create table test(id int,name varchar2(10));
Table created.
SQL> alter table test ROW ARCHIVAL;
Table altered.
SQL> insert into test values(1,'col1');
1 row created.
SQL> insert into test values(2,'col2');
1 row created.
SQL> commit;


SQL> COL DATA_TYPE FOR A10
SQL> COL COLUMN_NAME FOR A20

SQL> SELECT COLUMN_NAME, DATA_TYPE,  HIDDEN_COLUMN, CHAR_LENGTH  FROM USER_TAB_COLS WHERE TABLE_NAME='TEST';

COLUMN_NAME             DATA_TYPE  HID  CHAR_LENGTH
--------------------                      ----------    ---              -----------
ORA_ARCHIVE_STATE    VARCHAR2   YES        4000
NAME                                 VARCHAR2   NO           10
ID                                         NUMBER     NO            0

SQL> col ora_archive_state for a20

SQL> select id,name,ora_archive_state from test;



        ID NAME       ORA_ARCHIVE_STATE
---------- ---------- --------------------
         1 col1              0
         2 col2              0


預設情況下,ora_archive_state列的值為0,其意味著沒有在資料庫歸檔。

SQL> update test set ora_archive_state='1' where id=1;

1 row updated.

SQL> commit;

Commit complete.

SQL> select * from test;

        ID NAME
---------- ----------
         2 col2
可以看到,修改的那上資料已經看不到了。

SQL> ALTER SESSION SET ROW ARCHIVAL VISIBILITY = ALL;

Session altered.

SQL> select * from test;

        ID NAME
---------- ----------
         1 col1
         2 col2
SQL> ALTER SESSION SET ROW ARCHIVAL VISIBILITY=active;

Session altered.

SQL> select * from test;

        ID NAME
---------- ----------
         2 col2

可以看到,不同的會話參數,顯示結果不同。
















相關文章

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.