这几天在学习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 直接拷到命令行执行,就撤销了原有的事物。
flashback transaction query 结果.jpg
做了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 直接拷到命令行执行,就撤销了原有的事物。
flashback transaction query 结果.jpg
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24862808/viewspace-708138/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24862808/viewspace-708138/