国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

最簡單的Oracle數據恢復 select as of使用方法

2020-07-26 14:15:28
字體:
來源:轉載
供稿:網友

You perform a Flashback Query by using a SELECT statementwith an AS OF clause.You use a flashback query to restrieve data as it existed at some time in the past.The query explicitly references a past time by menasof timestamp or SCN.It returns committed data that was current at that point intime.
通過執行一個帶as of 子句的select語句進行閃回查詢,可以閃回檢索過去某個時間存在的數據,一個閃回查詢被用來重現過去存在過的數據,這個查詢明確的引用了過去的一個時間段或SCN號,閃回查詢返回的數據都是過去某時刻已經提交的數據。

Potential uses of Flashback Query include:
可能使用到閃回查詢的地方:
⊙Recovering lost data or undoing incorrect,committed changes.For example,if you mistakenly delete or update rows,and then commit them,you can immediately undo the mistake.
恢復丟失的數據或撤銷已經提交的錯誤。例如如果你不小心刪除或更新了行,并且做了提交操作,你可以立刻撤銷這個錯誤。
⊙Comparing current data with the corresponding data at some time in the past.For example,you might run a daily report that shows the change in data from yesterday.You can compare the individual rows of table data or find intersections or unions of sets of rows.
比較當前數據和歷史數據的一致性。例如,你可能需要生成一份前一天數據更新的日報告,你可以分別比較表的每一行或找到行的交集和并集。
⊙Checking the state of transactional data at a particular time.For example,you could verify the account balance of a certain day.
在某個特殊時間檢查事務型數據的狀態。例如,你可以在某一天驗證賬戶收支。
⊙Simplifying the application design,by removing the need to store some kinds of temporal data.By using a Flashback Query, you can retrieve past data directly from the database.
移除某些因需求儲存的暫時數據以簡化應用設計。通過閃回查詢你可以從數據庫中直接獲取到過去的數據。
⊙Applying the packaged applications such as report generation tools to past data.
使用包裝應用(例如報表生成工具)的歷史數據
⊙Providing self-service error correction for anapplication,thereby enabling users to undo and correct their errors.
為應用提供自服務錯誤更正,因此可以讓用戶撤銷或更正他們的錯誤。
 
示例:
 
SQL> conn /as sysdba;
已連接。
SQL> set pagesize 200
SQL> select * from scott.dept;
 
    DEPTNO DNAME                        LOC
---------- ---------------------------- -------------------------
        10 ACCOUNTING                   NEW YORK
        20 RESEARCH                     DALLAS
        30 SALES                         CHICAGO
        40 OPERATIONS                   BOSTON
現在,我們來增加一條數據,并提交:
 
SQL> insert into scott.dept values(50,'錯誤數據','CHINA');
已創建 1 行。
 
SQL> select * from scott.dept;


    DEPTNO DNAME                        LOC
---------- ---------------------------- -------------------------
        10 ACCOUNTING               NEW YORK
        20 RESEARCH                 DALLAS
        30 SALES                         CHICAGO
        40 OPERATIONS               BOSTON
        50 錯誤數據                     CHINA
 
SQL> commit;(2011-12-9 10:51:00)


提交完成。
正常情況下,由于已經做了commit操作,所以rollback已經無效了,要想得到2011-12-9 10:51:00之前的數據,怎么辦?
使用timestamp時間點閃回:
SQL> select * from scott.dept as of timestamp to_timestamp('2011-12-09 10:00:00','yyyy-mm-dd hh24:mi:ss');
 
    DEPTNO DNAME                        LOC
---------- ---------------------------- -------------------------
        10  ACCOUNTING                   NEW YORK
        20  RESEARCH                      DALLAS
        30  SALES                         CHICAGO
        40  OPERATIONS                   BOSTON
閃回查詢,主要依靠表空間的undo數據,如果想要追溯更久的數據,就需要設置較大的undo_tablespaces大小和undo_retention。
 
如果想直接更新當前的表到歷史的某個時間狀態,可以直接使用flashback關鍵字:
 
 
SQL> alter table scott.dept enable row movement;


表已更改。
 
SQL> flashback table scott.dept to timestamp to_timestamp('2011-12-09 10:00:00','yyyy-mm-dd hh24:mi:ss');


閃回完成。
 
【注意】:
閃回不是萬能的,當一個表的數據較大或時間過長時,如果沒有設置較大的閃回空間和時間,閃回操作將會失敗,可能會出現以下錯誤:

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 砀山县| 萝北县| 皮山县| 秭归县| 休宁县| 蒙自县| 砚山县| 裕民县| 兴化市| 枣阳市| 宽城| 师宗县| 清水河县| 张家口市| 石首市| 高州市| 福贡县| 盐津县| 沙湾县| 平陆县| 长武县| 祁东县| 阿荣旗| 墨竹工卡县| 同心县| 固镇县| 扶余县| 东乡族自治县| 塘沽区| 长泰县| 淄博市| 申扎县| 彝良县| 晋宁县| 崇信县| 浦县| 盐边县| 江口县| 沁阳市| 隆德县| 逊克县|