Sunday, March 29, 2009

Flashback Query

To find all the changes to the table during a certain period, issue the following query.

SQL> SELECT empno, ename, versions_starttime, versions_startscn, versions_endtime, versions_endscn, versions_xid, versions_operation
FROM emp
VERSIONS BETWEEN SCN 3816659800 AND 3816659980
/*where empno = 7900*/

Using the above query with where clause enables you to view the history of a table row over a period of time.

When the versions_endtime is null it means that the rows has not been changed yet.

In addition to SCN you can also use the timestamp as shown below.

SQL> SELECT empno, ename, sal, versions_starttime, versions_startscn, versions_endtime, versions_endscn, versions_xid, versions_operation
FROM emp
VERSIONS BETWEEN TIMESTAMP to_date('26/03/2009 09:45:00', 'dd/mm/yyyy hh24:mi:ss') and to_date('26/03/2009 09:52:00', 'dd/mm/yyyy hh24:mi:ss')
/*where empno = 7900*/

To view status of table at a particular time.

SQL> SELECT * FROM emp
AS OF TIMESTAMP to_date('26/03/2009 09:30:00', 'dd/mm/yyyy hh24:mi:ss');


Thanks

No comments:

Followers

Powered By Blogger
 

Oracle Database Administration. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com