一、查找表操作记录
1.首先查找表操作的历史记录
select * from v$sqlarea a where a.SQL_TEXT like ‘%表名%’;
2.从上面的记录中找到update语句对应的sql_id
select * from v$sqltext a,v$sqlarea b where a.SQL_ID=b.SQL_ID and b.SQL_ID in(‘cq53826tk4u3c’,‘afftnrfhu5utk’) order by b.LAST_ACTIVE_TIME desc;
3.从上面的记录中找到最新的sql操作记录,然后找到用户名和主机
select * from sys.v_$session l,sys.v_$sql s where s.SQL_ID=‘cq53826tk4u3c’ and l.USERNAME is not null;
二、恢复数据
//1.根据时间恢复
//示例:
select * from EMP;
delete from EMP where EMPNO=7369;
//查询当前电脑时间:
select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss’)from dual;
//查询删除之前数据:
select * from EMP as of timestamp to_timestamp(‘2018-04-12 09:12:11’,‘yyyy-mm-dd hh24:mi:ss’);
//恢复数据:
flashback table EMP to timestamp to_timestamp(‘2018-04-12 09:12:11’,‘yyyy-mm-dd hh24:mi:ss’);
//注意:若出现报错:ORA-08189:未启用行移动功能,不能闪回表;
//则:
alter table EMP enable row movement; //开启行移动功能
alter table EMP disable row movement; //关闭行移动功能
//2.根据数据库SCN恢复数据
//查询当前数据库SCN号:
select current_scn from v$database;(不能执行的话,切换到sys用户或system用户查询)
//查询到的当前值为:91799986
//缩小SCN号查询被删除表数据:(若无数据继续缩小SCN,由于数据库操作不止一人,SCN号变化比较多,可以多缩小几个号)
select * from 表名 as of scn 91799980;
//恢复数据:
flashback table 表名 to scn 91799980;
//恢复完成。若报错:ORA-08189:未启用行移动功能,不能闪回表;结果方案同上。
以上两种方式,笔者只实践了第一种,第二种还未实践。
原地址:https://blog.csdn.net/weixin_39864440/article/details/85261940