首页 > 数据库 > Oracle > Flashback Transaction
With Flashback Transaction Query, it is possible to identify all incorrect changes that were made to table and reverse them, maintaining referential integrity. The FLASHBACK_TRANSACTION_QUERY data dictionary view contains all information needed to identify the offending transaction. The same task can be accomplished with Enterprise Manager.
SQL> desc flashback_transaction_query; Name Null? Type ----------------------------------------- -------- ---------------------------- XID RAW(8) START_SCN NUMBER START_TIMESTAMP DATE COMMIT_SCN NUMBER COMMIT_TIMESTAMP DATE LOGON_USER VARCHAR2(30) UNDO_CHANGE# NUMBER OPERATION VARCHAR2(32) TABLE_NAME VARCHAR2(256) TABLE_OWNER VARCHAR2(32) ROW_ID VARCHAR2(19) UNDO_SQL VARCHAR2(4000)
The FLASHBACK_TRANSACTION_QUERY view contains all changes to the database, including DDL. Since UNDO space is finite, the value of OPERATION may be “unknown” for DML that is no longer in UNDO.
Prior to using Flashback Transaction Query, additional logging to the redo log stream is required. Also, the SELECT ANY TRANSACTION privilege as well as EXECUTE on the dbms.flashback stored procedure privileges are required.
SQL> alter database add supplemental log data; Database altered. SQL> alter database add supplemental log data (primary key) columns; Database altered. SQL> grant execute on dbms_flashback to hr; Grant succeeded. SQL> grant select any transaction to hr; Grant succeeded.
After deleting two rows from the test table, I can query the FLASHBACK_TRANSACTION_QUERY view to see the change. Additionaly, the UNDO_SQL column will list the logical opposite of the transactions to reconstruct the table to the way it was before the changes:
SQL> DELETE FROM test WHERE c1 IN (1,3);
2 rows deleted.
SQL> commit;
Commit complete.
SQL> select * from test;
C1 C2 C3
---------- --------- ----------
2 11-JUN-13 ghjk
4 11-JUN-13 wert
SQL> SELECT xid, start_scn, commit_scn, undo_sql
2 FROM flashback_transaction_query WHERE xid IN (
3 SELECT versions_xid FROM test VERSIONS BETWEEN TIMESTAMP
4 TO_TIMESTAMP('2013-06-11 08:35:00', 'YYYY-MM-DD HH24:MI:SS') AND
5 TO_TIMESTAMP('2013-06-11 08:50:00', 'YYYY-MM-DD HH24:MI:SS'));
XID START_SCN COMMIT_SCN
---------------- ---------- ----------
UNDO_SQL
--------------------------------------------------------------------------------
07000300AD1F0000 15698167 15698169
insert into "TEST"."TEST"("C1","C2","C3") values ('3',TO_DATE('08-JUN-13', 'DD-
MON-RR'),'zxcv');
07000300AD1F0000 15698167 15698169
insert into "TEST"."TEST"("C1","C2","C3") values ('1',TO_DATE('10-JUN-13', 'DD-
MON-RR'),'asdf');
To accomplish this task through Enterprise Manager, select “Schema”
from the Enterprise Manager home page and then select “tables.” Then
enter the desired schema and click go. After selecting a table, you can
select “Flashback Transaction Query” from the actions dropdown.
http://www.dba-stuff.com/?p=306
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/90618/viewspace-1133726/ ,如需转载,请注明出处,否则将追究法律责任。