flashback query,flashback

來源:互聯網
上載者:User

flashback query,flashback

FLASHBACK技術包括多個方面:flashback database,flashback drop,flashback query,flashback table

其中flashbackdatabase利用的是閃回日誌,flashback drop利用的資源回收筒,flashback query和 flashbacktable利用的是undo資訊。Flashbackquery可以協助我們確定在過去某個時間點或者時間段內表的資料是如何儲存的,而flashback table則是協助我們切切實實的將表閃回到過去的某個時間點。

 

Flashback query是在oracle 9i時引入的的,為的是協助我們查詢在過去某個時間點某表的資料狀態。文法格式為

Select * from table_name as of scnscn;

Select * from table_name as oftimestamp timestamp;

 

由於flashbackquery只可以查詢過去某個時間點的資訊,無法針對某一個時間段進行查詢,因此在10g中,oracle引入了flashbackversion query,文法格式如下:

Select  versions_xid,versions_startscn,versions_endscn,versions_starttime,versions_endtime,….From table_name versions between scn startscn and endscn;

Select  versions_xid,versions_startscn,versions_endscn,versions_starttime,versions_endtime,….From table_name versions between scn minvalue and maxvalue;

 

Select  versions_xid,versions_startscn,versions_endscn,versions_starttime,versions_endtime,….From table_name versions between timstamp starttime and endtime;

需要注意的是,flashback version query不可以跨越ddl執行

 

除了flashbackversion query外,oracle還為我們提供了flashback  transaction query,通過 flashback  transaction query 我們可以針對某一事務語句進行查詢,獲悉該事務所影響的表資料。文法格式如下:

 

Select * from flashback_transaction_query where xid = ??;

 

Flashback table可以將表閃回的之前的某個狀態,文法格式如下:

Flashbacktable table_name to scn scn;

Flashbacktable table_name to timestamp timestamp;

 

需要注意的是flashback table同樣不可以跨越ddl,但是如果我們僅僅是對錶執行了添加列的ddl操作,那麼我們是可以閃回到ddl之前的某個狀態的,只是新添加的列取值全部為空白。

 

Flashback table操作是通過暫存資料表對需要閃回的表進行了刪除和插入操作(刪除所有資料並重新插入所有資料),因此可能發生行的位置改變。

相關文章

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.