Flashback Transaction Query

You use a Flashback Version Query to retrieve the different versions of specific rows that existed during a given time interval. A new row version is created whenever aCOMMIT statement is executed.

You specify a Flashback Version Query using the VERSIONS BETWEEN clause of theSELECT statement. Here is the syntax:

VERSIONS {BETWEEN {SCN | TIMESTAMP} start AND end}

Table 10-1 Flashback Version Query Row Data Pseudocolumns

Pseudocolumn NameDescription

VERSIONS_STARTSCN

VERSIONS_STARTTIME

Starting System Change Number (SCN) or TIMESTAMP when the row version was created. This identifies the time when the data first took on the values reflected in the row version. You can use this to identify the past target time for a Flashback Table or Flashback Query operation.

If this is NULL, then the row version was created before the lower time bound of the queryBETWEEN clause.

VERSIONS_ENDSCN

VERSIONS_ENDTIME

SCN or TIMESTAMP when the row version expired. This identifies the row expiration time.

If this is NULL, then either the row version was still current at the time of the query or the row corresponds to aDELETE operation.

VERSIONS_XID

Identifier of the transaction that created the row version.

VERSIONS_OPERATION

Operation performed by the transaction: I for insertion, D for deletion, orU for update. The version is that of the row that was inserted, deleted, or updated; that is, the rowafter anINSERT operation, the row before a DELETE operation, or the row affected by an UPDATE operation.

Note: For user updates of an index key, a Flashback Version Query may treat anUPDATE operation as two operations,DELETE plus INSERT, represented as two version rows with aD followed by anI VERSIONS_OPERATION.


 

 

Here is a typical Flashback Version Query:

SELECT versions_startscn, versions_starttime, 
       versions_endscn, versions_endtime,
       versions_xid, versions_operation,
       name, salary  
  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')
  WHERE name = 'JOE';

SELECT xid, operation, start_scn,commit_scn, logon_user, undo_sql
     FROM flashback_transaction_query
     WHERE xid = HEXTORAW('000200030000002D');

 

 

 

举例:


SQL> create table t1 as  select *from dept;

表已创建。

SQL> insert into  t1 select * from dept where deptno=10;

已创建 1 行。

SQL> update  t1 set loc='a' where deptno=10;

已更新2行。

SQL> update  t1 set loc='b' where deptno=10;

已更新2行。

SQL> commit;

提交完成。

SQL> select  versions_xid, versions_operation,t1.*  from scott.t1 VERSIONS BETWEEN SCN MINVALUE AND M
AXVALUE where dname='ACCOUNTING' ;

VERSIONS_XID     VE     DEPTNO DNAME                        LOC
---------------- -- ---------- ---------------------------- --------------------------
04002300BF050000 U          10 ACCOUNTING                   b
                                               10 ACCOUNTING                   NEW YORK
04002300BF050000 I          10 ACCOUNTING                   b

SQL> select  versions_xid, versions_operation,t1.*  from scott.t1 VERSIONS BETWEEN SCN MINVALUE AND M
AXVALUE where dname='ACCOUNTING' ;

VERSIONS_XID     VE     DEPTNO DNAME                        LOC
---------------- -- ---------- ---------------------------- --------------------------
04002300BF050000 U          10 ACCOUNTING                   b
                                                 10 ACCOUNTING                   NEW YORK
04002300BF050000 I          10 ACCOUNTING                   b

 

 

举例二:

 


SQL> drop table t1;

表已删除。

SQL> create table t1  as  select * from dept;

表已创建。


SQL> update t1 set deptno=1 where dname='ACCOUNTING';

已更新 1 行。

SQL> update t1 set deptno=2 where dname='ACCOUNTING';

已更新 1 行。

SQL> update t1 set deptno=3 where dname='ACCOUNTING';

已更新 1 行。

SQL> alter table t1 drop column loc;

表已更改。

SQL> commit;

提交完成。

SQL> update t1 set deptno=4 where dname='ACCOUNTING';

已更新 1 行。

SQL> update t1 set deptno=5 where dname='ACCOUNTING';

已更新 1 行。

SQL> update t1 set deptno=6 where dname='ACCOUNTING';

已更新 1 行。

SQL> commit;

提交完成。


SQL> select  versions_xid, versions_operation,t1.*  from
AXVALUE where dname='ACCOUNTING' ;

VERSIONS_XID     VE     DEPTNO DNAME
---------------- -- ---------- --------------------------
0400020094050000 U           6 ACCOUNTING
                                                    3 ACCOUNTING
 


通过此例子告诉我们Flashback Transaction Query 只能是在commit以后的数据,只能是DML语句,ddl语句不行,DDL以后前面的DML语句查不到,不用开启row movement

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值