欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle 11g闪回flashback

程序员文章站 2022-06-01 17:51:34
...

Oracle 11g闪回flashback oracle9i的闪回: 闪回查询从9i引入,可以按照时间点或者SCN向前查 询,获取修改 前的数据。

Oracle 11g闪回flashback

oracle9i的闪回:
闪回查询从9i引入,可以按照时间点或者SCN向前查

询,获取修改 前的数据。

闪回查询依赖于回滚段中存储的数据前镜像,通过设置

undo_retention参数设置前镜像的保留时间。

查询的语法:

select … as of scn | timestamp

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as hr@JIAGULUN


SQL> select * from student;
ID NAME AGE
----------- -------------------- -----------
1 zhangsan 21
2 lisi 22
3 wangwu 23


SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYYMMDDHH24:
------------------------------
20150124 17:58:58


SQL>
SQL> update student s set s.name='mazi' where s.id = 1;
1 row updated


SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYYMMDDHH24:
------------------------------
20150124 18:02:56


SQL> delete from student s where s.name = 'lisi';
1 row deleted


SQL> select * from student;
ID NAME AGE
----------- -------------------- -----------
1 mazi 21
3 wangwu 23


SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYYMMDDHH24:
------------------------------
20150124 18:04:00


SQL> delete from student;
2 rows deleted


SQL> select * from student;
ID NAME AGE
----------- -------------------- -----------


SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYYMMDDHH24:
------------------------------
20150124 18:04:26


SQL> select * from student as of scn 3099731;
ID NAME AGE
----------- -------------------- -----------
1 zhangsan 21
2 lisi 22
3 wangwu 23

SQL> select * from student;
ID NAME AGE
----------- -------------------- -----------


SQL> commit;
Commit complete


SQL> insert into student values(1,'zhangsan',23);
1 row inserted


SQL> commit;
Commit complete


SQL>
SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYYMMDDHH24:
------------------------------
20150124 19:36:30


SQL>
SQL> delete from student;
1 row deleted


SQL> commit;
Commit complete


SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYYMMDDHH24:
------------------------------
20150124 19:36:51


SQL> select * from student as of timestamp to_date('20150124 19:36:30','yyyymmdd hh24:mi:ss');
ID NAME AGE
----------- -------------------- -----------
1 zhangsan 23


SQL> select * from student as of timestamp to_date('20150124 18:04:26','yyyymmdd hh24:mi:ss');
ID NAME AGE
----------- -------------------- -----------
1 zhangsan 21
2 lisi 22
3 wangwu 23


SQL>

oracle10g的闪回版本查询:
对于9i的闪回查询进行增强,Oracle10g提供了闪回版本

查询,因为9i的闪回查询仅仅能够得到过去某个时间点上的

数据,但是无法反映出一段时间内数据表中数据的变化,

10g的闪回版本查询可以对时间段内数据表的不同版本进行

查询。

闪回版本查询的语法:

select … from … versions between

其中,select后面可以选择伪列,来获得事务的开始、结

束时间、SCN号、ID号等。

SQL> select to_char(sysdate,'yyyymmdd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YYYYMMDDHH24:
------------------------------
20150124 19:40:11