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
3 comments:
My cousin recommended this blog and she was totally right keep up the fantastic work!
Medical Assistant Salary
Very important that oracle in this case understand "truncate" as changing table definition.
Thank you.
Hello, just wаnted to tell you, І еnjoyed thiѕ агticle.
It was funny. Keeр on posting!
Also vіsit my ωebsitе ... hcg drops for weight loss
Also see my web page - hcg drops vs injections
Post a Comment