Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1062137
  • 博文数量: 239
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 3618
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-12 13:17
文章分类

全部博文(239)

文章存档

2021年(1)

2016年(1)

2015年(30)

2014年(91)

2013年(116)

分类: LINUX

2014-01-30 15:37:33

1.闪回时间点查询

1.查询hr.employess在2014年1月30号下午1点40分37秒所有的行
SQL> select * from hr.employees as of timestamp to_timestamp('2014-01-30 13:40:37','YYYY-MM-DD HH24:MI:SS');


2.查询100号员工在2014年1月30号下午1点40分37年时候的薪水
SQL> select salary from hr.employees as of timestamp to_timestamp('2014-01-30 13:40:37','YYYY-MM-DD HH24:MI:SS') where employee_id = 100; 


    SALARY
----------
     24000


3.查询100号员工5分钟前的薪水
修改employee_id的工资为100000元
SQL> update hr.employees set salary = 100000 where employee_id = 100;


1 row updated.


查看五分钟之前员工号为100的工资
SQL> select salary from hr.employees as of timestamp (systimestamp - interval '5' minute) where employee_id = 100;  


    SALARY
----------
     24000


查看员工号100现在的工资
SQL> select salary from hr.employees where employee_id = 100;


    SALARY
----------
    100000


SQL> commit;


Commit complete.

 
4.查看100号员工在SCN为1154993时的工种


SQL> select current_scn from v$database;


CURRENT_SCN
-----------
    1154993


SQL> select job_id from hr.employees as of scn 1154993 where employee_id = 100;


JOB_ID
----------
AD_PRES 


5.将10分钟前的hr.employees表和1小时前的hr.departments表以department_id为条件关联(join)
SQL> select 
e.last_name,
d.department_name 
from 
hr.employees as of timestamp (systimestamp - interval '10' minute) e,
hr.departments as of timestamp (systimestamp - interval '1' hour) d
where e.department_id = d.department_id; 


LAST_NAME  DEPARTMENT_NAME
------------------------- ------------------------------
Whalen  Administration
Fay  Marketing
Hartstein  Marketing
Tobias  Purchasing
Colmenares  Purchasing
Baida  Purchasing
Raphaely  Purchasing
Khoo  Purchasing
Himuro  Purchasing
Mavris  Human Resources
Feeney  Shipping


···························································
------------------------- ------------------------------
Urman  Finance
Chen  Finance
Faviet  Finance
Sciarra  Finance
Greenberg  Finance
Gietz  Accounting
Higgins  Accounting


106 rows selected.




6.将100号员工的薪资修改到40分钟前的值
SQL> select salary from hr.employees where employee_id = 100;


    SALARY
----------
    100000


SQL> update hr.employees 
set salary = (select salary from hr.employees as of timestamp
(systimestamp - interval '40' minute)
where employee_id = 100)
where employee_id = 100;


1 row updated.


SQL> commit;


Commit complete.


SQL> select salary from hr.employees where employee_id = 100;


    SALARY
----------
     24000


阅读(598) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~