【閃回特性之閃回事務查詢】Flashback Transaction Query
使用閃回事務查詢來獲取在給定的時間範圍內指定事務或所有事務的後設資料和歷史資料,具體是透過查詢FLASHBACK_TRANSACTION_QUERY檢視,其中的UNDO_SQL列顯示與事務中執行的DML語句在邏輯上相反的SQL語句,可以使用這些SQL程式碼來回退在事務中執行的邏輯步驟。也有一些情況下UNDO_SQL的程式碼不是原始事務的準確的反轉的程式碼,例如UNDO_SQL的INSERT操作不可能使用與被刪除的行相同的ROWID,在表中重新插入被刪除的行。
下面的語句從FLASHBACK_TRANSACTION_QUERY檢視中查詢事務資訊,包括事務ID,操作,操作起始和結束SCN號,登陸使用者以及和事務邏輯操作相反的SQL語句。
點選(此處)摺疊或開啟
-
SELECT xid, operation, start_scn, commit_scn, logon_user, undo_sql
-
FROM flashback_transaction_query
- WHERE xid = HEXTORAW('000200030000002D');
點選(此處)摺疊或開啟
-
SELECT xid, logon_user
-
FROM flashback_transaction_query
-
WHERE xid IN (
-
SELECT versions_xid FROM employees VERSIONS BETWEEN TIMESTAMP
-
TO_TIMESTAMP('2003-07-18 14:00:00', 'YYYY-MM-DD HH24:MI:SS') AND
-
TO_TIMESTAMP('2003-07-18 17:00:00', 'YYYY-MM-DD HH24:MI:SS')
- );
首先,在scott使用者下建立測試表dept和emp。
點選(此處)摺疊或開啟
-
DROP TABLE emp;
-
CREATE TABLE emp (
-
empno NUMBER PRIMARY KEY,
-
empname VARCHAR2(16),
-
salary NUMBER
-
);
-
INSERT INTO emp (empno, empname, salary) VALUES (111, 'Mike', 555);
-
COMMIT;
-
-
DROP TABLE dept;
-
CREATE TABLE dept (
-
deptno NUMBER,
-
deptname VARCHAR2(32)
-
);
-
INSERT INTO dept (deptno, deptname) VALUES (10, 'Accounting');
- COMMIT;
點選(此處)摺疊或開啟
-
UPDATE emp SET salary = salary + 100 WHERE empno = 111;
-
INSERT INTO dept (deptno, deptname) VALUES (20, 'Finance');
-
DELETE FROM emp WHERE empno = 111;
- COMMIT;
-
點選(此處)摺疊或開啟
-
INSERT INTO emp (empno, empname, salary) VALUES (111, 'Tom', 777);
-
UPDATE emp SET salary = salary + 100 WHERE empno = 111;
-
UPDATE emp SET salary = salary + 50 WHERE empno = 111;
- COMMIT;
點選(此處)摺疊或開啟
-
SQL>
-
SQL> SELECT versions_xid XID, versions_startscn START_SCN,
-
2 versions_endscn END_SCN, versions_operation OPERATION,
-
3 empname, salary
-
4 FROM emp
-
5 VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE
-
6 WHERE empno = 111;
-
-
XID START_SCN END_SCN OPERATION EMPNAME SALARY
-
---------------- ---------- ---------- --------- ---------------- ----------
-
0A001900BB180000 3291484 I Tom 927
-
0A000000BC180000 3291482 D Mike 555
-
3291482 Mike 555
-
- SQL>
點選(此處)摺疊或開啟
-
SQL>
-
SQL> SELECT xid, start_scn, commit_scn, operation, logon_user, undo_sql
-
2 FROM flashback_transaction_query
-
3 WHERE xid = HEXTORAW('0A000000BC180000');
-
-
XID START_SCN COMMIT_SCN OPERATION LOGON_USER UNDO_SQL
-
---------------- ---------- ---------- -------------------------------- ------------------------------ --------------------------------------------------------------------------------
-
0A000000BC180000 3291472 3291482 DELETE SCOTT insert into "SCOTT"."EMP"("EMPNO","EMPNAME","SALARY") values ('111','Mike','655');
-
0A000000BC180000 3291472 3291482 INSERT SCOTT delete from "SCOTT"."DEPT" where ROWID = 'AAAOhDAAEAAAADQAAB';
-
0A000000BC180000 3291472 3291482 UPDATE SCOTT update "SCOTT"."EMP" set "SALARY" = '555' where ROWID = 'AAAOhBAAEAAAADAAAA';
-
0A000000BC180000 3291472 3291482 BEGIN SCOTT
-
- SQL>
點選(此處)摺疊或開啟
-
SQL>
-
SQL> SELECT xid, start_scn, commit_scn, operation, table_name, table_owner
-
2 FROM flashback_transaction_query
-
3 WHERE table_owner = 'SCOTT'
-
4 AND start_timestamp >=
-
5 TO_TIMESTAMP ('2015-04-16 11:00:00','YYYY-MM-DD HH:MI:SS');
-
-
-
XID START_SCN COMMIT_SCN OPERATION TABLE_NAME TABLE_OWNER
-
---------------- ---------- ---------- -------------------------------- -------------------------------------------------------------------------------- --------------------------------
-
090012009B020000 3291408 3291410 INSERT EMP SCOTT
-
0A001900BB180000 3291483 3291484 UPDATE EMP SCOTT
-
0A001900BB180000 3291483 3291484 UPDATE EMP SCOTT
-
0A001900BB180000 3291483 3291484 INSERT EMP SCOTT
-
0A000000BC180000 3291472 3291482 DELETE EMP SCOTT
-
0A000000BC180000 3291472 3291482 INSERT DEPT SCOTT
-
0A000000BC180000 3291472 3291482 UPDATE EMP SCOTT
-
0A001200BC180000 3291470 3291472 INSERT DEPT SCOTT
-
-
8 rows selected
-
- SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30162081/viewspace-1579545/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 聊聊閃回事務查詢Flashback Transaction Query
- oracle flashback特性(1.4)--閃回查詢之Transaction queryOracle
- [閃回特性之閃回版本查詢]Flashback Version Query
- 全面學習oracle flashback特性(1.4)--閃回查詢之Transaction queryOracle
- 【徵文】全面學習oracle flashback特性(1.4)--閃回查詢之Transaction queryOracle
- Flashback Query閃回查詢
- 閃回版本查詢(Flashback Version Query)
- 閃回版本查詢與閃回事務查詢
- 聊聊閃回版本查詢Flashback Version Query
- oracle flashback特性(1.2)--閃回查詢之As of scnOracle
- 【閃回特性之閃回查詢】使用閃回查詢(select as of)
- oracle flashback特性(1.1)--閃回查詢之As of timestampOracle
- Oracle 11G 閃回技術 閃回版本查詢和閃回事務查詢Oracle
- oracle flashback特性(1.5)--閃回查詢之制約因素Oracle
- Oracle閃回查詢,閃回版本查詢與閃回事務查詢的使用區別總結Oracle
- 全面學習oracle flashback特性(1.2)--閃回查詢之As of scnOracle
- 閃回查詢之閃回版本查詢
- 閃回查詢之閃回表查詢
- flashback query閃回資料
- 使用FLASHBACK_TRANSACTION_QUERY查詢回滾事務SQLSQL
- 【Flashback】使用檢視快速獲得Flashback Query閃回查詢資料
- 全面學習oracle flashback特性(1.1)--閃回查詢之As of timestampOracle
- 【徵文】全面學習oracle flashback特性(1.2)--閃回查詢之As of scnOracle
- Oracle 11G 閃回技術 使用Oracle閃回事務查詢Oracle
- 全面學習oracle flashback特性(1.5)--閃回查詢之制約因素Oracle
- 【徵文】全面學習oracle flashback特性(1.1)--閃回查詢之As of timestampOracle
- Oracle 閃回特性(FLASHBACK DATABASE)OracleDatabase
- 【備份恢復】 閃回技術之閃回事務處理查詢
- 【徵文】全面學習oracle flashback特性(1.5)--閃回查詢之制約因素Oracle
- Oracle閃回技術--Flashback Version QueryOracle
- 閃回表、閃回查詢
- 閃回之 Flashback Query (dml表、過程、函式、包等)、Flashback version Query函式
- 對錶誤操作的閃回恢復--flashback_transaction_query檢視
- 閃回(關於閃回查詢)
- 閃回刪除、閃回查詢
- 閃回查詢
- Oracle9i Flashback Query 閃回查詢總結 --- (通過SCN恢復)Oracle
- 基本閃回查詢和閃回表