I don't "undrop" table a lot. So once when I tried to "undrop" a table, I got an error:
sql> undrop table test1;
SP2-0734:unknown command beginning "undrop tab..." - rest of line ignored.
Well, I soon found, it's not "undrop", instead:
SQL> flashback table test1 to before drop rename to test2;
Flashback complete.
You can rename it if the previous name has been used by others.
Showing posts with label flashback. Show all posts
Showing posts with label flashback. Show all posts
Tuesday, February 13, 2007
Thursday, August 17, 2006
Oracle Flashback Query Using AS OF TIMESTAMP
Since Oracle 9i Release 2, you can use "AS OF SCN | TIMESTAMP" flashback query to query the "before" data of a changed table. It's useful to find the changes you made or recover errors.
I used TIMESTAMP more often and found it simple but efficient. I'll show some examples below.
I used TIMESTAMP more often and found it simple but efficient. I'll show some examples below.
SQL> select salary from employees where employee_id = 100;Here shows the way to query the "before" data of yesterday:
SALARY
----------
24000
SQL> update employees set salary = salary * 1.05 where employee_id = 100;
1 row updated.
SQL> commit;
SQL> select salary from employees where employee_id = 100;
SALARY
----------
25200
SQL> select salary from employees AS OF TIMESTAMP sysdate - 1 where employee_id = 100;To show ten (10) minutes ago:
SALARY
----------
24000
select salary from employees AS OF TIMESTAMP sysdate - 10/60/24 where employee_id = 100;Or you can use function SYSTIMESTAMP instead of sysdate.
select salary from employees AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '1' DAY) where employee_id = 100;To recover the change:
select salary from employees AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '10' MINUTE) where employee_id = 100;
SQL>update employees e1 set salary =
( select salary from employees AS OF TIMESTAMP sysdate - 1 e2
where e2.employee_id = e1.employee_id )
where employee_id = 100;
1 row updated.
SQL> select salary from employees where employee_id = 100;You may sometimes want to save the before data to a temporary table, then compare and reccover.
SALARY
----------
24000
create table tmp_employees nologging as select * from employees AS OF TIMESTAMP sysdate - 1;The SELECT ... AS OF will not work after the table structure changes or table truncation.
SQL> truncate table tmp_objects;
Table truncated.
SQL> select count(*) from tmp_objects as of timestamp sysdate - 1/24/60;
ORA-01466: unable to read data - table definition has changed
Location:
Mississauga, ON, Canada
Subscribe to:
Posts (Atom)