Oracle 11G Flashback Technology uses Oracle Flashback Query

Flashback query using SELECT statement with AS OF clause . Flashback Query fetches data from a previous point in time.

Statements explicitly refer to past times by timestamp or SCN . Returns the data that has been committed at that point in time.

Uses of Flashback Query include:

1. Recover lost data, undo incorrect and committed changes. For example, if you delete or update a row by mistake and commit, you can immediately undo the error.

2. Compare current data with earlier data. For example, you can run a daily report to show the change in data from yesterday to today.

You can compare individual rows; you can also view the intersection and union of sets of rows.

3. View the status of transaction data at a specific time. For example, account balances for a particular day can be verified.

4. Simplifies application design by eliminating the need to store some types of temporary data. Oracle allows you to get past data directly from the database.

5. Apply packaged applications to past data, such as report generation tools.

6. Provides error-correcting self-services for applications, allowing users to undo and change their errors.

Example A. Checking and Restoring Past Data
Suppose at 12:30 PM that the data row corresponding to employee Chung was deleted from the employees table. And you know that at 9:30 AM Chung's data is normal in the database. The missing data can be found by using a flashback query to view the contents of the table at 9:30 AM. Data can be restored if needed.

-- use flashback query to get missing rows

SELECT*FROM employees

ASOFTIMESTAMP TO_TIMESTAMP('2004-04-04 09:30:00','YYYY-MM-DD HH:MI:SS')

WHERE last_name ='Chung';

 

-- restore missing rows using flashback query

INSERTINTO employees (

  SELECT*FROM employees

  ASOFTIMESTAMP TO_TIMESTAMP('2004-04-04 09:30:00','YYYY-MM-DD HH:MI:SS')

  WHERE last_name ='Chung'

);


Oracle Flashback Query Guide

1. The AS OF clause can be specified or omitted for each table , and different times can be specified for different tables.

Note : If a table is a Flashback Data Archive and the specified time is earlier than the time it was created, the query will return 0 rows without causing an error.

2. The AS OF clause can be used in queries to perform DDL operations (such as creating and truncating tables),

Can also be used to perform DML operations ( INSERT , DELETE ) in the same session as Flashback Query .

3. Use the results of flashback queries in DDL statements or DML statements that affect the current state of the database ,

The AS OF clause can be used in an INSERT or CREATE TABLE AS SELECT statement .

4. If in the application, this 3 second error is important for the flashback query, use the SCN instead of the timestamp.

5. You can use the data referenced by the created view, that is , use the AS OF clause in the SELECT statement defined by the view.

If you specify a relative time that is subtracted from the current time on the database host, the time is recalculated for each query.

CREATEVIEW hour_ago AS

  SELECT*FROM employees ASOFTIMESTAMP(SYSTIMESTAMP -INTERVAL'60'MINUTE);

6. AS OF clauses can be used in self-join or set operations to extract and compare data from different times.

The results of a flashback query can be stored by preceding the flashback query with CREATE TABLE AS SELECT or INSERT INTO TABLE SELECT .

INSERTINTO employees

(SELECT*FROM employees ASOFTIMESTAMP(SYSTIMESTAMP -INTERVAL'60'MINUTE))

MINUS

SELECT*FROM employees);

 

 

 

Original:    http://blog.itpub.net/17013648/viewspace-1167134/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326269670&siteId=291194637