分为闪回版本查询和闪回事务查询两步,可针对事务进行闪回,比9i更进一步。
SQL> create table test1 as select 1 a, 2 b from dual;
Table created
SQL> insert into test1 values(2,2);
1 row inserted
SQL> insert into test1 values(3,3);
1 row inserted
SQL> insert into test1 values(4,4);
1 row inserted
SQL> insert into test1 values(5,5);
1 row inserted
SQL> update test1 set a = 55 where a = 5;
1 row updated
SQL> delete from test1 where a = 4;
1 row deleted
SQL> commit;
Commit complete
SQL> select versions_starttime, versions_endtime, versions_xid, versions_operation, a, b from test1 versions between timestamp minvalue and maxvalue;
VERSIONS_STARTTIME VERSIONS_ENDTIME VERSIONS_XID VERSIONS_OPERATION A B
------------------ ---------------- ---------------- ------------------ -- --
1 2
23-8月 0200200012020000 I 55 5
23-8月 0200200012020000 I 3 3
23-8月 0200200012020000 I 2 2
SQL> desc flashback_transaction_query;
Name Type Nullable Default Comments
---------------- -------------- -------- ------- -----------------------------------------
XID RAW(8) Y Transaction identifier
START_SCN NUMBER Y Transaction start SCN
START_TIMESTAMP DATE Y Transaction start timestamp
COMMIT_SCN NUMBER Y Transaction commit SCN
COMMIT_TIMESTAMP DATE Y Transaction commit timestamp
LOGON_USER VARCHAR2(30) Y Logon user for transaction
UNDO_CHANGE# NUMBER Y 1-based undo change number
OPERATION VARCHAR2(32) Y forward operation for this undo
TABLE_NAME VARCHAR2(256) Y table name to which this undo applies
TABLE_OWNER VARCHAR2(32) Y owner of table to which this undo applies
ROW_ID VARCHAR2(19) Y rowid to which this undo applies
UNDO_SQL VARCHAR2(4000) Y SQL corresponding to this undo
SQL> select * from flashback_transaction_query where xid = '0200200012020000';
XID START_SCN START_TIMESTAMP COMMIT_SCN COMMIT_TIMESTAMP LOGON_USER UNDO_CHANGE# OPERATION TABLE_NAME TABLE_OWNER ROW_ID UNDO_SQL
---------------- --------- --------------- ---------- ---------------- ------------------------------ ------------ -------------------------------- -------------------------------------------------------------------------------- -------------------------------- ------------------- --------------------------------------------------------------------------------
0200200012020000 1411203 2007-08-23 7:59 1411268 2007-08-23 8:00: TEST 1 DELETE TEST1 TEST AAAM9fAAGAAAAONAAC insert into "TEST"."TEST1"("A","B") values ('4','4');
0200200012020000 1411203 2007-08-23 7:59 1411268 2007-08-23 8:00: TEST 2 UPDATE TEST1 TEST AAAM9fAAGAAAAONAAD update "TEST"."TEST1" set "A" = '5' where ROWID = 'AAAM9fAAGAAAAONAAD';
0200200012020000 1411203 2007-08-23 7:59 1411268 2007-08-23 8:00: TEST 3 INSERT TEST1 TEST AAAM9fAAGAAAAONAAD delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAD';
0200200012020000 1411203 2007-08-23 7:59 1411268 2007-08-23 8:00: TEST 4 INSERT TEST1 TEST AAAM9fAAGAAAAONAAC delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAC';
0200200012020000 1411203 2007-08-23 7:59 1411268 2007-08-23 8:00: TEST 5 INSERT TEST1 TEST AAAM9fAAGAAAAONAAB delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAB';
0200200012020000 1411203 2007-08-23 7:59 1411268 2007-08-23 8:00: TEST 6 INSERT TEST1 TEST AAAM9fAAGAAAAONAAA delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAA';
0200200012020000 1411203 2007-08-23 7:59 1411268 2007-08-23 8:00: TEST 7 BEGIN
7 rows selected
SQL> desc test1;
Name Type Nullable Default Comments
---- ------ -------- ------- --------
A NUMBER Y
B NUMBER Y
SQL> begin
2 for i in 1..10 loop
3 insert into test1 values(i+10,i+100);
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed
SQL> commit;
Commit complete
SQL> delete from test1 where rownum < 4;
3 rows deleted
SQL> commit;
Commit complete
SQL> update test1 set a = 111 where rownum < 4;
3 rows updated
SQL> commi;t
2
SQL> commit;
Commit complete
SQL> select * from test1;
A B
-- --
11 5
11 10
11 10
13 10
14 10
15 10
16 10
17 10
18 10
19 10
20 11
11 rows selected
SQL> select * from test1 versions between timestamp minvalue and maxvalue;
A B
-- --
1 2
1 2
11 10
11 10
11 5
3 3
2 2
20 11
19 10
18 10
17 10
16 10
15 10
14 10
13 10
12 10
11 10
55 5
3 3
2 2
20 rows selected
SQL> select a,b,versions_xid, versions_name from test1 versions between timestamp minvalue and maxvalue;
select a,b,versions_xid, versions_name from test1 versions between timestamp minvalue and maxvalue
ORA-00904: "VERSIONS_NAME": 标识符无效
SQL> select a,b,versions_xid, versions_operation from test1 versions between timestamp minvalue and maxvalue;
A B VERSIONS_XID VERSIONS_OPERATION
-- -- ---------------- ------------------
1 2 0800240011020000 D
1 2
11 10 030024000D020000 U
11 10 030024000D020000 U
11 5 030024000D020000 U
3 3 0800240011020000 D
2 2 0800240011020000 D
20 11 06001A0011020000 I
19 10 06001A0011020000 I
18 10 06001A0011020000 I
17 10 06001A0011020000 I
16 10 06001A0011020000 I
15 10 06001A0011020000 I
14 10 06001A0011020000 I
13 10 06001A0011020000 I
12 10 06001A0011020000 I
11 10 06001A0011020000 I
55 5 0200200012020000 I
3 3 0200200012020000 I
2 2 0200200012020000 I
20 rows selected
SQL> select a,b,versions_xid, versions_operation, versions_starttime, versions_endtime from test1 versions between timestamp minvalue and maxvalue;
A B VERSIONS_XID VERSIONS_OPERATION VERSIONS_STARTTIME VERSIONS_ENDTIME
-- -- ---------------- ------------------ ------------------ ----------------
1 2 0800240011020000 D 23-8月
1 2 23-8月
11 10 030024000D020000 U 23-8月
11 10 030024000D020000 U 23-8月
11 5 030024000D020000 U 23-8月
3 3 0800240011020000 D 23-8月
2 2 0800240011020000 D 23-8月
20 11 06001A0011020000 I 23-8月
19 10 06001A0011020000 I 23-8月
18 10 06001A0011020000 I 23-8月
17 10 06001A0011020000 I 23-8月
16 10 06001A0011020000 I 23-8月
15 10 06001A0011020000 I 23-8月
14 10 06001A0011020000 I 23-8月
13 10 06001A0011020000 I 23-8月
12 10 06001A0011020000 I 23-8月 23-8月
11 10 06001A0011020000 I 23-8月 23-8月
55 5 0200200012020000 I 23-8月 23-8月
3 3 0200200012020000 I 23-8月 23-8月
2 2 0200200012020000 I 23-8月 23-8月
20 rows selected
SQL> select a,b,versions_xid, versions_operation, to_date(versions_starttime, 'yyyy-mm-dd'), versions_endtime from test1 versions between timestamp minvalue and maxvalue;
select a,b,versions_xid, versions_operation, to_date(versions_starttime, 'yyyy-mm-dd'), versions_endtime from test1 versions between timestamp minvalue and maxvalue
ORA-01861: 文字与格式字符串不匹配
SQL> select a,b,versions_xid, versions_operation, versions_starttime, versions_endtime from test1 versions between timestamp minvalue and maxvalue;
A B VERSIONS_XID VERSIONS_OPERATION VERSIONS_STARTTIME VERSIONS_ENDTIME
-- -- ---------------- ------------------ ------------------ ----------------
1 2 0800240011020000 D 23-8月
1 2 23-8月
11 10 030024000D020000 U 23-8月
11 10 030024000D020000 U 23-8月
11 5 030024000D020000 U 23-8月
3 3 0800240011020000 D 23-8月
2 2 0800240011020000 D 23-8月
20 11 06001A0011020000 I 23-8月
19 10 06001A0011020000 I 23-8月
18 10 06001A0011020000 I 23-8月
17 10 06001A0011020000 I 23-8月
16 10 06001A0011020000 I 23-8月
15 10 06001A0011020000 I 23-8月
14 10 06001A0011020000 I 23-8月
13 10 06001A0011020000 I 23-8月
12 10 06001A0011020000 I 23-8月 23-8月
11 10 06001A0011020000 I 23-8月 23-8月
55 5 0200200012020000 I 23-8月 23-8月
3 3 0200200012020000 I 23-8月 23-8月
2 2 0200200012020000 I 23-8月 23-8月
20 rows selected
SQL> select undo_sql from flashback_transaction_query where xid = '0800240011020000';
UNDO_SQL
--------------------------------------------------------------------------------
insert into "TEST"."TEST1"("A","B") values ('3','3');
insert into "TEST"."TEST1"("A","B") values ('2','2');
insert into "TEST"."TEST1"("A","B") values ('1','2');
SQL> select undo_sql from flashback_transaction_query where xid = '030024000D020000';
UNDO_SQL
--------------------------------------------------------------------------------
update "TEST"."TEST1" set "A" = '12' where ROWID = 'AAAM9fAAGAAAAONAAF';
update "TEST"."TEST1" set "A" = '11' where ROWID = 'AAAM9fAAGAAAAONAAE';
update "TEST"."TEST1" set "A" = '55' where ROWID = 'AAAM9fAAGAAAAONAAD';
SQL> select undo_sql from flashback_transaction_query where xid = '06001A0011020000';
UNDO_SQL
--------------------------------------------------------------------------------
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAN';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAM';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAL';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAK';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAJ';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAI';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAH';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAG';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAF';
delete from "TEST"."TEST1" where ROWID = 'AAAM9fAAGAAAAONAAE';
11 rows selected