Search This Blog

Friday, November 20, 2009

Flashback version query

Loading data
select current_scn from v$database;
insert into katerina.vt1 values(1);
insert into katerina.vt1 values(2);
insert into katerina.vt1 values(3);
insert into katerina.vt1 values(4);
commit;
select current_scn from v$database;
update katerina.vt1 set id=10 where id=1;
delete katerina.vt1 where id=2;
commit;
update katerina.vt1 set id=100 where id=10;
delete katerina.vt1 where id=3;
commit;
insert into katerina.vt1 values(2);
insert into katerina.vt1 values(3);
commit;


select
versions_startscn,
versions_endscn,
versions_xid,
versions_operation,
id
from katerina.vt1
versions between scn minvalue and maxvalue;

VERSIONS_STARTSCN VERSIONS_ENDSCN VERSIONS_XID V ID
----------------- --------------- ---------------- - ----------
9343741 06000400C5050000 I 3
9343741 06000400C5050000 I 2
9343739 04001A00A8040000 D 3
9343739 04001A00A8040000 U 100
9342873 020002009C050000 D 2
9342873 9343739 020002009C050000 U 10
9342868 01002B005B040000 I 4
9342868 9343739 01002B005B040000 I 3
9342868 9342873 01002B005B040000 I 2
9342868 9342873 01002B005B040000 I 1


Interpreat the results
=======================
My table has 4 rows


select
versions_startscn,
versions_endscn,
versions_xid,
versions_operation,
id
from katerina.vt1
versions between scn minvalue and maxvalue
AS OF SCN 9342873;

VERSIONS_STARTSCN VERSIONS_ENDSCN VERSIONS_XID V ID
----------------- --------------- ---------------- - ----------
9342873 020002009C050000 D 2
9342873 020002009C050000 U 10
9342868 01002B005B040000 I 4
9342868 01002B005B040000 I 3
9342868 9342873 01002B005B040000 I 2
9342868 9342873 01002B005B040000 I 1


select
id
from katerina.vt1
AS OF SCN 9342868;


ID
----------
1
2
3
4
select
id

from katerina.vt1
AS OF SCN 9342873;

ID
----------
10
3
4