加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码网 (https://www.900php.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

最简单的Oracle数据恢复 select as of使用方法

发布时间:2016-11-27 21:37:44 所属栏目:大数据 来源:站长网
导读:You perform a Flashback Query by using a SELECT statementwith an AS OF clause.You use a flashback query to restrieve data as it existed at some time in the past.The query explicitly references a past time by menasof timestamp or SCN.It r

You perform a Flashback Query by using a SELECT statementwith an AS OF clause.You use a flashback query to restrieve data as it existed at some time in the past.The query explicitly references a past time by menasof timestamp or SCN.It returns committed data that was current at that point intime.
通过执行一个带as of 子句的select语句进行闪回查询,可以闪回检索过去某个时间存在的数据,一个闪回查询被用来重现过去存在过的数据,这个查询明确的引用了过去的一个时间段或SCN号,闪回查询返回的数据都是过去某时刻已经提交的数据。

Potential uses of Flashback Query include:
可能使用到闪回查询的地方:
⊙Recovering lost data or undoing incorrect,committed changes.For example,if you mistakenly delete or update rows,and then commit them,you can immediately undo the mistake.
恢复丢失的数据或撤销已经提交的错误。例如如果你不小心删除或更新了行,并且做了提交操作,你可以立刻撤销这个错误。
⊙Comparing current data with the corresponding data at some time in the past.For example,you might run a daily report that shows the change in data from yesterday.You can compare the individual rows of table data or find intersections or unions of sets of rows.
比较当前数据和历史数据的一致性。例如,你可能需要生成一份前一天数据更新的日报告,你可以分别比较表的每一行或找到行的交集和并集。
⊙Checking the state of transactional data at a particular time.For example,you could verify the account balance of a certain day.
在某个特殊时间检查事务型数据的状态。例如,你可以在某一天验证账户收支。
⊙Simplifying the application design,by removing the need to store some kinds of temporal data.By using a Flashback Query, you can retrieve past data directly from the database.
移除某些因需求储存的暂时数据以简化应用设计。通过闪回查询你可以从数据库中直接获取到过去的数据。
⊙Applying the packaged applications such as report generation tools to past data.
使用包装应用(例如报表生成工具)的历史数据
⊙Providing self-service error correction for anapplication,thereby enabling users to undo and correct their errors.
为应用提供自服务错误更正,因此可以让用户撤销或更正他们的错误。
nbsp;
示例:
nbsp;
SQLgt; conn /as sysdba;
已连接。
SQLgt; set pagesize 200
SQLgt; select * from scott.dept;
nbsp;
nbsp;nbsp;nbsp; DEPTNO DNAMEnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; LOC
---------- ---------------------------- -------------------------
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 10 ACCOUNTINGnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; NEW YORK
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 20 RESEARCHnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; DALLAS
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 30 SALESnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; CHICAGO
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 40 OPERATIONSnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; BOSTON
现在,我们来增加一条数据,并提交:
nbsp;
SQLgt; insert into scott.dept values(50,'错误数据','CHINA');
已创建 1 行。
nbsp;
SQLgt; select * from scott.dept;


nbsp;nbsp;nbsp; DEPTNO DNAMEnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; LOC
---------- ---------------------------- -------------------------
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 10 ACCOUNTINGnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; NEW YORK
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 20 RESEARCHnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; DALLAS
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 30 SALESnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; CHICAGO
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 40 OPERATIONSnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; BOSTON
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 50 错误数据nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; CHINA
nbsp;
SQLgt; commit;(2011-12-9 10:51:00)


提交完成。
正常情况下,由于已经做了commit操作,所以rollback已经无效了,要想得到2011-12-9 10:51:00之前的数据,怎么办?
使用timestamp时间点闪回:
SQLgt; select * from scott.dept as of timestamp to_timestamp('2011-12-09 10:00:00','yyyy-mm-dd hh24:mi:ss');
nbsp;
nbsp;nbsp;nbsp; DEPTNO DNAMEnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; LOC
---------- ---------------------------- -------------------------
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 10nbsp; ACCOUNTINGnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; NEW YORK
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 20nbsp; RESEARCHnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; DALLAS
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 30nbsp; SALESnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; CHICAGO
nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 40nbsp; OPERATIONSnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; BOSTON
闪回查询,主要依靠表空间的undo数据,如果想要追溯更久的数据,就需要设置较大的undo_tablespaces大小和undo_retention。
nbsp;
如果想直接更新当前的表到历史的某个时间状态,可以直接使用flashback关键字:
nbsp;
nbsp;
SQLgt; alter table scott.dept enable row movement;


表已更改。
nbsp;
SQLgt; flashback table scott.dept to timestamp to_timestamp('2011-12-09 10:00:00','yyyy-mm-dd hh24:mi:ss');


闪回完成。
nbsp;
【注意】:
闪回不是万能的,当一个表的数据较大或时间过长时,如果没有设置较大的闪回空间和时间,闪回操作将会失败,可能会出现以下错误:

最简单的Oracle数据恢复 select as of使用方法

最简单的Oracle数据恢复 select as of使用方法

(编辑:源码网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读