oracle 10g flashback version query 和 flashback transaction query實驗

xfhuangfu發表於2015-07-04
這幾天在學習oracle10g的 flashback ,參考oracle的官方文件
做了flashback version query 和flashback transaction 的實驗,
記錄下來,便於以後查閱

OS: redhat linux as 4 u2
DB: oracle10gr2

Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.



C:\>sqlplus sxit/sxit@ora10hha

SQL*Plus: Release 10.1.0.2.0 - Production on 星期四 6月 30 13:59:42 2011

Copyright (c) 1982, 2004, Oracle.  All rights reserved.


連線到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create table emp
    (empno number,
      empname varchar2(16),
        salary number);

表已建立。

SQL> insert into emp values (111,'mike',555);

已建立 1 行。

SQL> commit ;
  

提交完成。

SQL> create table dept
        (deptno number,
           deptname varchar2(32));

表已建立。

SQL> insert into dept values (10,'accounting');

已建立 1 行。

SQL> commit;

提交完成。

接下來,簡單模擬不小心刪掉資料

SQL> update emp set salary =salary +100 where empno=111;

已更新 1 行。

SQL> insert into dept values(20,'finance');

已建立 1 行。

SQL> delete from emp where empno=111;

已刪除 1 行。

SQL> commit;

提交完成。


Subsequently, a new transaction reinserts employee id 111 with a new employee name into the emp table.


SQL> insert into emp values (111,'tom',777);

已建立 1 行。



SQL> update emp set salary =salary +100 where empno=111;

已更新 1 行。

SQL> update emp set salary =salary +50 where empno=111;

已更新 1 行。

SQL> commit;

提交完成。


此時發現誤操作了,想要查詢之前所做的修改。於是,通過
flashback  version query  查詢



C:\>sqlplus system@ora10hha

SQL*Plus: Release 10.1.0.2.0 - Production on 星期四 6月 30 14:08:19 2011

Copyright (c) 1982, 2004, Oracle.  All rights reserved.

請輸入口令:

連線到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> SELECT versions_xid XID, versions_startscn START_SCN,
            versions_endscn END_SCN, versions_operation OPERATION,
             empname, salary FROM sxit.emp
             VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE
          where empno=111;

XID               START_SCN    END_SCN OP EMPNAME
---------------- ---------- ---------- -- --------------------------------
    SALARY
----------
05002100A6000000     876197            I  tom
       927

07000E00A0000000     876146            D  mike
       555

05001A00A7000000     875980     876146 I  mike
       555


通過flashback version query  查到了誤操作時候的XID,並通過

flashback transaction query 找到相關的撤銷語句



SELECT  xid, start_scn , commit_scn ,
        operation , logon_user ,
        undo_sql FROM flashback_transaction_query
        WHERE xid = HEXTORAW('07000E00A0000000');

執行結果見附件中的圖片,然後根據附件中的undo_sql 直接拷到命令列執行,就撤銷了原有的事物。
oracle 10g flashback version query 和 flashback transaction query實驗
flashback transaction query 結果.jpg

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24862808/viewspace-708138/,如需轉載,請註明出處,否則將追究法律責任。

相關文章