четверг, 3 марта 2011 г.

Как вернуть прошлое состояние записи в Oracle?

В Oracle имеется очень полезная штука: возможность возвращать прошлое состояние записи (а также таблицы, базы).
(Перевод одной из глав с сайта oracle.com)

Использование в Oracle технологии возврата прошлого состояния.
Эта глава описывает, как использовать имеющуюся в Oracle возможность восстанавливать прошлое состояние записей.

Обзор технологии возврата к прошлым состояниям в Oracle

Example of Examining and Restoring Past Data

Suppose that you discover at 12:30 PM that the row for employee Chung was deleted from the employees table, and you know that at 9:30AM the data for Chung was correctly stored in the database. You can use Oracle Flashback Query to examine the contents of the table at 9:30 AM to find out what data was lost. If appropriate, you can restore the lost data.

Example 13-1 retrieves the state of the record for Chung at 9:30AM, April 4, 2004:
Example 13-1 Retrieving a Lost Row with Oracle Flashback Query
SELECT * FROM employees
  AS OF TIMESTAMP
   TO_TIMESTAMP('2004-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
     WHERE last_name = 'Chung';
Example 13-2 restores Chung's information to the employees table:
Example 13-2 Restoring a Lost Row After Oracle Flashback Query
INSERT INTO employees
  (SELECT * FROM employees
     AS OF TIMESTAMP
       TO_TIMESTAMP('2004-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
         WHERE last_name = 'Chung');
 



ориг. ссылка: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28424/adfns_flashback.htm#i1008579