20150124 19:52:15? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 13000100FE000000 U? ? ? ? ? ? ? ? ? ? ? ? ? 1 wangwu? ? ? ? ? ? ? ? ? 23
20150124 19:51:29 20150124 19:52:15 12001F00FF000000 I? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 zhangsan? ? ? ? ? ? ? ? 23
SQL>
过一段时间你会发现查询的结果变少了:
SQL> select? to_char( versions_starttime,'yyyymmdd hh24:mi:ss') ,to_char( versions_endtime,'yyyymmdd hh24:mi:ss'),versions_xid,versions_operation,id,name,age from student
? 2? versions between timestamp minvalue and maxvalue;
TO_CHAR(VERSIONS_STARTTIME,'YY TO_CHAR(VERSIONS_ENDTIME,'YYYY VERSIONS_XID VERSIONS_OPERATION? ? ? ? ? ID NAME? ? ? ? ? ? ? ? ? ? AGE
------------------------------ ------------------------------ ---------------- ------------------ ----------- -------------------- -----------
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2 mazi? ? ? ? ? ? ? ? ? ? ? 24
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1 wangwu? ? ? ? ? ? ? ? ? 23
SQL>
这是因为undo_retention这个值设置的时间到期了。
?
oracle10g的闪回事务查询:
? ? ? Oracle10g可以进行基于闪回版本查询的恢复,就是闪回事务查询。
? ? ? 从flashback_transaction_query中查询引起数据变化的
? ? 事务,和撤销事务的SQL语句,就是查询 operation和undo_sql 列。
?
SQL> select xid,start_timestamp,operation,undo_sql from flashback_transaction_query where table_name='STUDENT';
XID? ? ? ? ? ? START_TIMESTAMP OPERATION? ? ? ? ? ? ? ? UNDO_SQL
---------------- --------------- -------------------------------- --------------------------------------------------------------------------------
0F00020002010000 24-1月-15 20:32: UNKNOWN? ? ? ? ? ? ? ?
0F00040002010000 24-1月-15 20:32: UNKNOWN? ? ? ? ? ? ? ?
0F00040002010000 24-1月-15 20:32: UNKNOWN? ? ? ? ? ? ? ?
13000100FE000000 24-1月-15 19:52: UNKNOWN? ? ? ? ? ? ? ?
1400200004010000 24-1月-15 20:32: UNKNOWN? ?
? ? ? ? ? ?
如上图所示的,但是这里查不出来奇怪了。。。。
通过undo_sql来进行回滚事务(就是再做次反向操作)
?
?
oracle10g的闪回表:
Oracle10g的闪回表是把表里的数据回退到以前的某个时
刻或者SCN上。
? ? 特点:可以在线操作;自动恢复相关的属性,包括索引、
触发器等。
? ? 前提:对表启用行迁移。
? ? 语法:
? ? flashback table
Connected as hr@JIAGULUN
SQL> select * from student;
? ? ? ? ID NAME? ? ? ? ? ? ? ? ? ? AGE
----------- -------------------- -----------
? ? ? ? ? 3 zhangsan? ? ? ? ? ? ? ? 21
SQL> alter table student enable row movement;
Table altered
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
? ? ? ? ? ? ? ? 3143334
SQL> delete from student where id in(1);
0 rows deleted
SQL> delete from student where id in(3);
1 row deleted
SQL> commit;
Commit complete
SQL>? flashback? table student to scn 3143334;
Done
SQL> select * from student;
? ? ? ? ID NAME? ? ? ? ? ? ? ? ? ? AGE
----------- -------------------- -----------
? ? ? ? ? 3 zhangsan? ? ? ? ? ? ? ? 21
SQL>?
?
? ? 注意:sys的表不能闪回。
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as sys@JIAGULUN AS SYSDBA
SQL> select * from student;
? ? ? ? ID NAME? ? ? ? ? ? ? ? ? ? AGE
----------- -------------------- -----------
? ? ? ? ? 1 zhangsan? ? ? ? ? ? ? ? 20
? ? ? ? ? 2 lisi? ? ? ? ? ? ? ? ? ? ? ? ? 21
? ? ? ? ? 3 wangwu? ? ? ? ? ? ? ? ? 22
SQL> alter table student enable row movement;
Table altered
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
? ? ? ? ? ? ? ? 3142994
SQL> delete from student where id in(1,2);
2 rows deleted
SQL> commit;
Commit complete
SQL> select * from student;
? ? ? ? ID NAME? ? ? ? ? ? ? ? ? ? AGE
----------- -------------------- -----------
? ? ? ? ? 3 wangwu? ? ? ? ? ? ? ? ? 22
SQL> flashback? table student to scn 3142994;
flashback? table student t