Oracle Flashback Transaction Query with Oracle Flashback Version Query
Oracle Flashback Transaction Query with Oracle Flashback Version Query
In this example, a database administrator does this:
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;
Now emp and dept have one row each. In terms of row versions, each table has one version of one row. Suppose that an erroneous transaction deletes empno 111 from table emp:
UPDATE emp SET salary = salary + 100 WHERE empno = 111;
INSERT INTO dept (deptno, deptname) VALUES (20, 'Finance');
DELETE FROM emp WHERE empno = 111;
COMMIT;
Next, a transaction reinserts empno 111 into the emp table with a new employee name:
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;
The database administrator detects the application error and must diagnose the problem. The database administrator issues this query to retrieve versions of the rows in the emp table that correspond to empno 111. The query uses Oracle Flashback Version Query pseudocolumns:
SELECT versions_xid XID, versions_startscn START_SCN,
versions_endscn END_SCN, versions_operation OPERATION,
empname, salary
FROM emp
VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE
WHERE empno = 111;
Results are similar to:
XID START_SCN END_SCN O EMPNAME SALARY
---------------- ---------- ---------- - ---------------- ----------
09001100B2200000 10093466 I Tom 927
030002002B210000 10093459 D Mike 555
0800120096200000 10093375 10093459 I Mike 555 3 rows selected.
The results table rows are in descending chronological order. The third row corresponds to the version of the row in the table emp that was inserted in the table when the table was created. The second row corresponds to the row in emp that the erroneous transaction deleted. The first row corresponds to the version of the row in emp that was reinserted with a new employee name.
The database administrator identifies transaction 030002002B210000 as the erroneous transaction and uses Oracle Flashback Transaction Query to audit all changes made by this transaction:
SELECT xid, start_scn, commit_scn, operation, logon_user, undo_sql
FROM flashback_transaction_query
WHERE xid = HEXTORAW('000200030000002D');
Results are similar to:
XID START_SCN COMMIT_SCN OPERATION LOGON_USER
---------------- ---------- ---------- --------- ------------------------------
UNDO_SQL
-------------------------------------------------------------------------------- 030002002B210000 10093452 10093459 DELETE HR
insert into "HR"."EMP"("EMPNO","EMPNAME","SALARY") values ('111','Mike','655'); 030002002B210000 10093452 10093459 INSERT HR
delete from "HR"."DEPT" where ROWID = 'AAATjuAAEAAAAJrAAB'; 030002002B210000 10093452 10093459 UPDATE HR
update "HR"."EMP" set "SALARY" = '555' where ROWID = 'AAATjsAAEAAAAJ7AAA'; 030002002B210000 10093452 10093459 BEGIN HR 4 rows selected.
To make the result of the next query easier to read, the database administrator uses these SQL*Plus commands:
COLUMN operation FORMAT A9
COLUMN table_name FORMAT A10
COLUMN table_owner FORMAT A11
To see the details of the erroneous transaction and all subsequent transactions, the database administrator performs this query:
SELECT xid, start_scn, commit_scn, operation, table_name, table_owner
FROM flashback_transaction_query
WHERE table_owner = 'HR'
AND start_timestamp >=
TO_TIMESTAMP ('2002-04-16 11:00:00','YYYY-MM-DD HH:MI:SS');
Results are similar to:
XID START_SCN COMMIT_SCN OPERATION TABLE_NAME TABLE_OWNER
---------------- ---------- ---------- --------- ---------- -----------
02000E0074200000 10093435 10093446 INSERT DEPT HR
030002002B210000 10093452 10093459 DELETE EMP HR
030002002B210000 10093452 10093459 INSERT DEPT HR
030002002B210000 10093452 10093459 UPDATE EMP HR
0800120096200000 10093374 10093375 INSERT EMP HR
09001100B2200000 10093462 10093466 UPDATE EMP HR
09001100B2200000 10093462 10093466 UPDATE EMP HR
09001100B2200000 10093462 10093466 INSERT EMP HR 8 rows selected.
Oracle Flashback Transaction Query with Oracle Flashback Version Query的更多相关文章
- Oracle Database Transaction Isolation Levels 事务隔离级别
Overview of Oracle Database Transaction Isolation Levels Oracle 数据库提供如下事务隔离级别: 已提交读隔离级别 可串行化隔离级别 只读隔 ...
- Flashback Version Query、Flashback Transaction Query快速闪回细粒度数据
Flashback Version Query 闪回版本查询 使用Flashback Version Query 返回在指定时间间隔或SCN间隔内的所有版本,一次commit命令就会创建一个版本. ...
- Oracle 六闪回技术,flashback
Flashback 技术基于Undo segment基于内容的, 因此,限制UNDO_RETENTON参数. 要使用flashback 特征,您必须启用自己主动撤销管理表空间. 在Oracle 11g ...
- 闪回之 Flashback Query (dml表、过程、函数、包等)、Flashback version Query
Flashback Query 背景:Flashback 是 ORACLE 自 9i 就开始提供的一项特性,在 9i 中利用oracle 查询多版本一致的特点,实现从回滚段中读取表一定时间内操作过的数 ...
- 利用flashback transaction query新特性进行事务撤销
具备了flashback version query查询的基础,我们就可以进行基于flashback version query的恢复.这就是flashback transaction query.f ...
- [Oracle维护工程师手记]为什么flashback 的时候既需要 flashback log ,又需要 archive log?
为什么flashback 的时候既需要 flashback log ,又需要 archive log 呢? 如果数据库的活动不是很频繁,可以看到,其flashback log 是比较小的.那么是通过怎 ...
- Obtaining Query Count Without executing a Query in Oracle D2k
Obtaining Query Count Without executing a Query in Oracle D2k Obtaining a count of records that will ...
- Freebie - Utility Form: Generate Excel Report From SQL Query In Oracle Forms 6i And 11g
Sharing a form to generate Excel file report from SQL query in Oracle Forms. This form can be used i ...
- Create Data Block Based On From Clause Query In Oracle Forms
Example is given below to create a data block based on From Clause query in Oracle Forms. The follow ...
随机推荐
- C#多播委托详解
包含多个方法的委托成为多播委托,调用多播委托,可以按照顺序连续调用多个方法,因此,委托的签名就必须返回void;否则,就只能得到委托调用的最好一个方法的结果 1.多播委托可以用运算符"+&q ...
- http协议是无状态协议,它的无状态指的是什么,如何解决这种情况
http是无状态的协议,也是不安全的协议, 它的无状态是指对于事务处理没有记忆能力,缺少状态意味着后续的操作需要前面的信息. 解决办法:1,通过cookie解决,2,通过session会话保存.
- UIDynamic物理引擎
iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟 ...
- DOMContentLoaded和load的区别
一.概念 DOMContentLoaded 当初始的 HTML 文档被完全加载和解析完成之后,DOMContentLoaded 事件被触发,而无需等待样式表.图像和子框架的完成加载. load loa ...
- C++函数声明与定义
一个C++函数,如果没有函数声明而只有函数定义,程序照样运行,但要求这个函数定义必须放在main函数之前,否则编译按照从上到下的顺序扫描下来,就会出现编译器不认识它的情况. 如果一个程序同时有函数声明 ...
- oracle给用户赋dblink权限
create database link 别名(可任意起) connect to 需要连接库的用户名identified by 需要连接库的用户名 using '(DESCRIPTION =(ADDR ...
- PAT Advanced 1031 Hello World for U (20 分)
Given any string of N (≥) characters, you are asked to form the characters into the shape of U. For ...
- C++ STL(标准模板库)
一.STL简介 STL(Standard Template Library,标准模板库)是惠普实验室开发的,在被引入C++之前该技术就已经存在了很长的一段时间. STL的代码从广义上讲分为三类:alg ...
- JS比较两个时间的时间差
/** * 比较两个时间的时间差 * @param startTime 开始时间 * @param endTime 结束时间 * @demo compareTime(new Date('2019-12 ...
- python3:类和实例
面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...