1启用数据库的flashback
SQL> alter database flashback on;
alter database flashback on
*
第 1 行出现错误:
ORA-38706: 无法启用 FLASHBACK DATABASE 事件记录。
ORA-38707: 尚未启用介质恢复。
SQL> alter database archivelog;
数据库已更改。
SQL> alter database flashback on;
数据库已更改。
SQL> show parameter recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string D:\oracle\product\10.2.0\rmanb
ak
db_recovery_file_dest_size big integer 5G
recovery_parallelism integer 0
SQL> select SUPPLEMENTAL_LOG_DATA_MIN,SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_
DATA_UI,force_logging from v$database;
SUPPLEME SUP SUP FOR
-------- --- --- ---
NO NO NO NO
SQL> select * from test;
JOB_ID JOB_TITLE MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
AD_PRES President 20000 40000
AD_VP Administration Vice President 15000 30000
AD_ASST Administration Assistant 3000 6000
FI_MGR Finance Manager 8200 16000
FI_ACCOUNT Accountant 4200 9000
AC_MGR Accounting Manager 8200 16000
AC_ACCOUNT Public Accountant 4200 9000
.......
.......
**********************************闪回查询测试***********************************
查看当前scn
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
581698
删除一些数据
SQL> delete from test where job_id='FI_MGR';
已删除 1 行。
SQL> commit;
提交完成。
使用闪回查询,查看被删除的数据
SQL> select * from test as of scn 581698 where job_id='FI_MGR';
JOB_ID JOB_TITLE MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
FI_MGR Finance Manager 8200 16000
这样就可以将误删除的数据在插回表中了。
上面的是基于scn的查询,下面的是基于时间的查询
SQL> SELECT * FROM test AS OF TIMESTAMP TO_TIMESTAMP('2014-10-04 15:05:00', 'YY
YY-MM-DD HH:MI:SS') WHERE job_id='FI_MGR';
SELECT * FROM test AS OF TIMESTAMP TO_TIMESTAMP('2014-10-04 15:05:00', 'YYYY-MM
-DD HH:MI:SS') WHERE job_id='FI_MGR'
*
第 1 行出现错误:
ORA-01849: 小时值必须介于 1 和 12 之间
SQL> SELECT * FROM test AS OF TIMESTAMP TO_TIMESTAMP('2014-10-04 15:07:00', 'YY
YY-MM-DD HH24:MI:SS') WHERE job_id='FI_MGR';
JOB_ID JOB_TITLE MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
FI_MGR Finance Manager 8200 16000
*********************************************闪回表测试************************************
SQL> FLASHBACK TABLE test TO TIMESTAMP TO_TIMESTAMP('2014-10-04 15:05:00', 'YYYY
-MM-DD HH24:MI:SS')
2 ;
FLASHBACK TABLE test TO TIMESTAMP TO_TIMESTAMP('2014-10-04 15:05:00', 'YYYY-MM-D
D HH24:MI:SS')
*
第 1 行出现错误:
ORA-08189: 因为未启用行移动功能, 不能闪回表
SQL> alter table test enable row movement;
表已更改。
SQL> FLASHBACK TABLE test TO TIMESTAMP TO_TIMESTAMP('2014-10-04 15:07:00', 'YYYY
-MM-DD HH24:MI:SS');
闪回完成。
SQL> select * from test;
JOB_ID JOB_TITLE MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
AD_PRES President 20000 40000
AD_VP Administration Vice President 15000 30000
AD_ASST Administration Assistant 3000 6000
FI_MGR Finance Manager 8200 16000
FI_ACCOUNT Accountant 4200 9000
AC_MGR Accounting Manager 8200 16000
看到被删除的那行已经回来了
*************************************************************************