Oracle 9iR2可以利用flashback query來查詢undo的資料

Oracle 9iR2可以利用flashback query來查詢undo的資料,
只要是Undo的資料尚未被覆寫,就有機會把資料還原。

先將測試tmp_ccc內的資料清除
SQL> select count(1) from tmp01;

  COUNT(1)
----------
        10

SQL> delete tmp01 ;

10 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(1) from tmp01;

  COUNT(1)
----------
         0


1、利用SCN查詢
找出現在的SCN
SQL> SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM dual;

GET_SYSTEM_CHANGE_NUMBER
----------------------------
                 450302

查詢tmp01在SCN 450301時的資料
SELECT count(1) FROM tmp01 AS OF SCN 450301;

  COUNT(1)
----------
        10

2、利用時間查詢

找30分鐘前的資料
select count(1) from tmp_ccc AS OF TIMESTAMP TO_TIMESTAMP(sysdate-30/1440);

  COUNT(1)
----------
        10
         
也可以直接指定時間,先設定時間格式
SQL> ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'DD-MON-YYYY HH24:MI:SS';

Session altered.

查現在的時間,看看時間格式
SQL> SELECT LOCALTIMESTAMP   FROM   dual;

LOCALTIMESTAMP
---------------------------------------------------------------------------
27-DEC-2013 15:59:19

SQL> SELECT count(1) FROM tmp01 AS OF TIMESTAMP TO_TIMESTAMP('27-DEC-2013 15:29:00');

  COUNT(1)
----------
        10