---
title: "Oracle中恢复某张表丢失数据的方法"
author: "xmt721"
date: "2010-12-30T23:14:06Z"
tags: ["Blog", "C", "C#", "C++", "Oracle"]
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2010-12-30T23:14:06Z"
id: 856388
url: "https://xmt721.iteye.com/blog/856388"
---

Oracle中恢复某张表丢失数据的方法

2010-05-15 16:55

--利用ORACLE数据库的SCN进行恢复，ORACLE数据库每隔5分钟，系统会产生一个系统时间标记与scn的匹配并存入sys.smon\_scn\_time表中。

--我们对这个备份机制做如下测试

--查询出来数据  
select t.\*, t.rowid from account t where id &gt;10000 order by t.id asc;

--删掉数据  
delete from account c where c.id &gt;10000;

--查询出ORACLE数据库中的scn与时间的对应关系  
select * from sys.smon\_scn\_time order by time\_dp desc;

--根据数据取得删除时间段对应的SCN号，这里是1693760， 查看这个检查点的account表的历史情况  
select * from account as of scn 1693760;

-- 将account表复制一个，（这里表的关联关系需要另外处理），命名为account\_new 。  
create table account\_new as select * from account where 1&lt;&gt;1

--将删掉的数据库从这个检查点恢复到新表account\_new中。  
insert into account\_new (select * from account as of scn 1693760);

--查询恢复后的结果。  
select * from account\_new;

--- 此方法的最佳恢复时间越短越好，如果超过了24个小时，恢复的可能性就很小了。

引用自：[http://hi.baidu.com/no9988/blog/item/c1dc2fecaf92da2b62d09ff6.html](http://hi.baidu.com/no9988/blog/item/c1dc2fecaf92da2b62d09ff6.html)