1.创建一表并插入数据
SQL> create table t (x int,name varchar2(10));
表已创建。
SQL> insert into t values(1,'a');
已创建 1 行。
SQL> insert into t values(2,'b');
已创建 1 行。
SQL> insert into t values(3,'b');
已创建 1 行。
SQL> insert into t values(4,'d');
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
X NAME
---------- ----------
1 a
2 b
3 b
4 d
2.查询当前SCN
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
967014
3.删除一行
SQL> delete from t where x=4;
已删除 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
X NAME
---------- ----------
1 a
2 b
3 b
4.闪回查询
SQL> select * from t as of scn 967014;
X NAME
---------- ----------
1 a
2 b
3 b
4 d
把scn转成时间
SQL> select scn_to_timestamp(967014) from dual;
SCN_TO_TIMESTAMP(967014)
--------------------------------------------------
05-7月 -14 07.41.13.000000000 下午
按时间闪回查询
SQL> select * from t as of timestamp to_date('2014-7-5 19:41:00','yyyy-mm-dd hh24:mi:ss');
X NAME
---------- ----------
1 a
2 b
3 b
4 d
5.恢复数据
SQL> insert into t select * from t as of timestamp to_date('2014-7-5 19:41:00','yyyy-mm-dd hh24:mi:ss') where x=4;
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
X NAME
---------- ----------
1 a
2 b
3 b
4 d
SQL> create table t (x int,name varchar2(10));
表已创建。
SQL> insert into t values(1,'a');
已创建 1 行。
SQL> insert into t values(2,'b');
已创建 1 行。
SQL> insert into t values(3,'b');
已创建 1 行。
SQL> insert into t values(4,'d');
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
X NAME
---------- ----------
1 a
2 b
3 b
4 d
2.查询当前SCN
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
967014
3.删除一行
SQL> delete from t where x=4;
已删除 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
X NAME
---------- ----------
1 a
2 b
3 b
4.闪回查询
SQL> select * from t as of scn 967014;
X NAME
---------- ----------
1 a
2 b
3 b
4 d
把scn转成时间
SQL> select scn_to_timestamp(967014) from dual;
SCN_TO_TIMESTAMP(967014)
--------------------------------------------------
05-7月 -14 07.41.13.000000000 下午
按时间闪回查询
SQL> select * from t as of timestamp to_date('2014-7-5 19:41:00','yyyy-mm-dd hh24:mi:ss');
X NAME
---------- ----------
1 a
2 b
3 b
4 d
5.恢复数据
SQL> insert into t select * from t as of timestamp to_date('2014-7-5 19:41:00','yyyy-mm-dd hh24:mi:ss') where x=4;
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
X NAME
---------- ----------
1 a
2 b
3 b
4 d
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26937943/viewspace-1210453/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26937943/viewspace-1210453/