自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用視圖快速獲得Flashback Query閃回查詢數(shù)據(jù)

數(shù)據(jù)庫 Oracle
本文給出使用視圖協(xié)助我們快速構(gòu)造閃回查詢內(nèi)容,通過視圖可以方便的檢索“歷史上的數(shù)據(jù)”。

[[207758]]

本文給出使用視圖協(xié)助我們快速構(gòu)造閃回查詢內(nèi)容,通過視圖可以方便的檢索“歷史上的數(shù)據(jù)”。

1.構(gòu)造閃回查詢視圖需求描述

1)準(zhǔn)備員工表和工資表

2)刪除工資表中雇傭年限在1994年之前的記錄

3)創(chuàng)建視圖可以查詢工資表刪除之前的記錄

2.準(zhǔn)備環(huán)境

1)準(zhǔn)備員工表和工資表

  1. sec@ora10g> create table emp (id number,name varchar2(20), e_date date); 
  2.  
  3. Table created. 
  4.  
  5. sec@ora10g> create table salary (id number, salary number); 
  6.  
  7. Table created.  

emp表包含員工ID、員工名字和雇傭時(shí)間信息;

salary表中包含員工ID和薪水信息。

2)初始化數(shù)據(jù)

  1. insert into emp values (1,'Secooler',to_date('1991-01-01','yyyy-mm-dd')); 
  2.  
  3. insert into emp values (2,'Andy',to_date('1992-01-01','yyyy-mm-dd')); 
  4.  
  5. insert into emp values (3,'HOU',to_date('2010-01-01','yyyy-mm-dd')); 
  6.  
  7. insert into emp values (4,'Shengwen',to_date('2011-01-01','yyyy-mm-dd')); 
  8.  
  9. commit
  10.  
  11. insert into salary values (1,60000); 
  12.  
  13. insert into salary values (2,50000); 
  14.  
  15. insert into salary values (3,40000); 
  16.  
  17. insert into salary values (4,30000); 
  18.  
  19. commit 

3)獲取初始化數(shù)據(jù)內(nèi)容

  1. sec@ora10g> select * from emp; 
  2.  
  3. ID NAME E_DATE 
  4.  
  5. ---------- ------------------------------ ----------------- 
  6.  
  7. 1 Secooler 19910101 00:00:00 
  8.  
  9. 2 Andy 19920101 00:00:00 
  10.  
  11. 3 HOU 20100101 00:00:00 
  12.  
  13. 4 Shengwen 20110101 00:00:00 
  14.  
  15. sec@ora10g> select * from salary; 
  16.  
  17. ID SALARY 
  18.  
  19. ---------- ---------- 
  20.  
  21. 1 60000 
  22.  
  23. 2 50000 
  24.  
  25. 3 40000 
  26.  
  27. 4 30000  

3.為構(gòu)造后續(xù)的閃回查詢查詢當(dāng)前的時(shí)間和SCN號

1)查詢當(dāng)前時(shí)間

  1. sec@ora10g> select sysdate from dual; 
  2.  
  3. SYSDATE 
  4.  
  5. ----------------- 
  6.  
  7. 20110809 21:34:11 
  8.  
  9. 2)查詢當(dāng)前系統(tǒng)SCN號 
  10.  
  11. sec@ora10g> select dbms_flashback.get_system_change_number from dual; 
  12.  
  13. GET_SYSTEM_CHANGE_NUMBER 
  14.  
  15. ------------------------ 
  16.  
  17. 3141326 

4.刪除工資表中雇傭年限在1994年之前的記錄

  1. sec@ora10g> delete from salary where id in ( select id from emp where e_date < to_date('1994','yyyy')); 
  2.  
  3. rows deleted. 
  4.  
  5. sec@ora10g> commit
  6.  
  7. Commit complete. 
  8.  
  9. sec@ora10g> select * from emp; 
  10.  
  11. ID NAME E_DATE 
  12.  
  13. ---------- ------------------------------ ----------------- 
  14.  
  15. 1 Secooler 19910101 00:00:00 
  16.  
  17. 2 Andy 19920101 00:00:00 
  18.  
  19. 3 HOU 20100101 00:00:00 
  20.  
  21. 4 Shengwen 20110101 00:00:00 
  22.  
  23. sec@ora10g> select * from salary; 
  24.  
  25. ID SALARY 
  26.  
  27. ---------- ---------- 
  28.  
  29. 3 40000 
  30.  
  31. 4 30000  

此時(shí),在salary表中1994年之前的員工信息已經(jīng)被刪除,并且數(shù)據(jù)修改已經(jīng)提交。

5.兩種方法創(chuàng)建視圖構(gòu)造閃回查詢刪除之前的數(shù)據(jù)

1)***種方法:使用時(shí)間戳來構(gòu)造閃回查詢視圖

  1. sec@ora10g> create view v_salary_timestamp as select * from salary as of timestamp to_timestamp('2011-08-09 21:34:11','YYYY-MM-DD HH24:MI:SS'); 
  2.  
  3. View created.  

2)第二種方法:使用SCN構(gòu)造閃回查詢視圖

  1. sec@ora10g> create view v_salary_scn as select * from salary as of scn 3141326; 
  2.  
  3. View created.  

6.使用視圖獲取閃回查詢數(shù)據(jù)

  1. sec@ora10g> select * from v_salary_timestamp; 
  2.  
  3. ID SALARY 
  4.  
  5. ---------- ---------- 
  6.  
  7. 1 60000 
  8.  
  9. 2 50000 
  10.  
  11. 3 40000 
  12.  
  13. 4 30000 
  14.  
  15. sec@ora10g> select * from v_salary_scn; 
  16.  
  17. ID SALARY 
  18.  
  19. ---------- ---------- 
  20.  
  21. 1 60000 
  22.  
  23. 2 50000 
  24.  
  25. 3 40000 
  26.  
  27. 4 30000  

到此,兩種構(gòu)造視圖的方法都順利的獲得了閃回查詢的數(shù)據(jù)。順利的完成任務(wù)。

7.小結(jié)

Oracle的閃回查詢功能本身的能耐自不必多說。使用視圖將閃回查詢語句進(jìn)行一次“封裝”后,我們便得到了另外一種直觀的便利。 

責(zé)任編輯:龐桂玉 來源: Oracle疑點(diǎn)通
相關(guān)推薦

2014-07-02 15:37:49

PLSQL

2024-11-13 08:00:00

PostgreSQ插件開發(fā)

2020-08-17 14:56:02

PythonSQL

2010-04-07 17:27:38

Oracle 11g

2018-01-22 13:01:15

數(shù)據(jù)庫MySQLbinlog

2011-08-09 13:14:37

Oracle 10g數(shù)據(jù)庫閃回

2009-06-18 09:47:50

2024-07-04 07:44:19

2010-04-15 11:41:21

Oracle 數(shù)據(jù)庫

2010-04-15 11:33:39

Oracle數(shù)據(jù)庫

2011-08-05 13:17:34

Oracle數(shù)據(jù)庫閃回個(gè)性

2024-07-02 10:00:55

2010-04-15 12:43:06

Oracle數(shù)據(jù)庫

2016-12-26 22:52:34

互聯(lián)網(wǎng)大數(shù)據(jù)融資

2009-06-29 09:00:42

Hibernate的Q

2010-07-27 14:26:08

DB2數(shù)據(jù)庫物化視圖

2019-10-11 09:55:53

數(shù)據(jù)工具架構(gòu)

2017-11-20 11:23:12

MySQLMyFlash閃回工具

2019-10-21 08:08:34

MySQL數(shù)據(jù)庫主鍵

2010-07-12 15:49:53

MS SQL Serv
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號