工作中有时会遇到误删数据,或者想要把数据恢复到某个时间的操作。这里找到了两种方法来实现:scn和时间戳两种方法恢复。但是如果需要恢复的表在这段时间内表结构有过调整,那就无法通过这种方式恢复了。
一、通过scn恢复删除且已提交的数据
1、获得当前数据库的scn号
select current_scn from v$database;
2、查询当前scn号之前的scn
select * from 表名 as of scn xxxxx;
3、恢复删除且已提交的数据
flashback table 表名 to scn xxxxx;
二、通过时间恢复删除且已提交的数据
1、查询当前系统时间
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
2、查询删除数据的时间点的数据
select * from 表名 as of timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');
3、恢复删除且已提交的数据
flashback table 表名 to timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');
注意:如果在执行上面的语句,出现错误。可以尝试执行 alter table 表名 enable row movement; //允许更改时间戳
数据泵导入
impdp xxx/password@orcl DUMPFILE=xxx.DMP TABLESPACES=xxxSpace remap_schema=xxxUser:aaaUser remap_tablespace=xxxSpace:aaaSpace table_exists_action=replace
数据泵导出
expdp xxx/password directory=DUMP_DIR DUMPFILE=xxx.dmp schemas=xxxUser;