1. 程式人生 > >Oracle:多版本和閃回

Oracle:多版本和閃回

閃回庫

普通使用者使用dbms_flashback包,必須通過管理員授權。命令如下:

grant execute on dbms_flashback to scott;

快閃記憶體到10分鐘之前

DBMS_FLASHBACK.ENABLE_AT_TIME(SYSDATE-10/1440 )

閃回表:

1. 查詢兩個小時前的某表資料

select * from business_apply as of timestamp sysdate-2/12
select * from t as of timestamp to_timestamp(‘2013-10-25 08:57:47’, ‘yyyy-mm-dd hh24:mi:ss’);
select sysdate-1/12 from dual;

2. 資料庫誤刪除表之後恢復:

flashback table t to before drop;

通過版本號閃回

總結
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss’) time,
to_char(dbms_flashback.get_system_change_number) scn
from dual;
select * from t as of scn 11220804149;

多版本和閃回:


variable SCN number
exec :scn :=dbms_flashback.get_system_change_number
print scn
select
* from guaranty_contract;
delete from guaranty_contract; select count(*) from guaranty_contract AS OF SCN:scn; select * from (select count(*) from guaranty_contract),(select count(*) from guaranty_contract as of scn :scn); flashback table guaranty_contract to scn :scn; ALTER TABLE guaranty_contract ENABLE ROW
MOVEMENT;
select * from (select count(*) from guaranty_contract,(select count(*) from guaranty_contract as of scn :scn)