oracle 10g flashback version query 和 flashback transaction query实验

这几天在学习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 直接拷到命令行执行,就撤销了原有的事物。
20110630_2434a64f871f60c86a69EX7S1EjCZzTB.jpg
flashback transaction query 结果.jpg

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24862808/viewspace-708138/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24862808/viewspace-708138/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值