вторник, 19 ноября 2013 г.

Restore table changes back in time (as of timestamp)

restore table changes back in time
====================================
<><><><><><><><><><><><><><><><><><><><><><><><>
Let me introduce the table called PHONE_BOOK:
<><><><><><><><><><><><><><><><><><><><><><><><>
DESC PHONE_BOOK
Name       Null Type        
---------- ---- -------------
NUM             NUMBER      
NAME            VARCHAR2(100)
PROFESSION      VARCHAR2(100)
PHONE           VARCHAR2(100)
OTHER           VARCHAR2(100)

<><><><><><><><><><><><><><><><><><><><><><><><>
There are following values living
<><><><><><><><><><><><><><><><><><><><><><><><>
select name,other from PHONE_BOOK where  NAME like '%Evge%';
NAME   OTHER
================ ===========
Bashmak Evgeny  222-61-34
Botman Evgeny
Zelipuk Evgeny  299-46-14

<><><><><><><><><><><><><><><><><><><><><><><><>
Let's corrupt selected values
<><><><><><><><><><><><><><><><><><><><><><><><>
update phone_book
set    other = '77777777'
where  NAME like '%Evge%'
/

commit;
<><><><><><><><><><><><><><><><><><><><><><><><>
Haha, values become wrong:
<><><><><><><><><><><><><><><><><><><><><><><><>
select name,other from PHONE_BOOK where  NAME like '%Evge%';

NAME   OTHER
================ ===========
Bashmak Evgeny  77777777
Botman Evgeny  77777777
Zelipuk Evgeny  77777777

<><><><><><><><><><><><><><><><><><><><><><><><>
No worries, there is backup oportunity in the 11g
<><><><><><><><><><><><><><><><><><><><><><><><>
update phone_book
set    (other) =
          (select other
              from   phone_book as of timestamp systimestamp - 1/24 history
              where  history.NAME = phone_book.NAME
             )
/

commit;

<><><><><><><><><><><><><><><><><><><><><><><><>
Values back to the right values
<><><><><><><><><><><><><><><><><><><><><><><><>
select name,other from PHONE_BOOK where  NAME like '%Evge%';
NAME   OTHER
================ ===========
Bashmak Evgeny  222-61-34
Botman Evgeny
Zelipuk Evgeny  299-46-14

Комментариев нет:

Отправить комментарий