1. 查询当前表数据:
select a.*,a.rowid from student a;
2.删除表中数据:
删除的方式是这样的
如果通过:truncate table student;将表中的数据清除,那么表结构就发生了改变,那么就不能进行闪回查询了,进行闪回查询的时候就会报 [ORA-01466:无法读取表数据,表定义已更改]错误。也就是说,进行闪回查询的前提条件就是表结构不能发生改变。
3. 删除之后马上进行查询系统当前时间
select sysdate from dual;--记录下来当前时间(这个只是为了测试数据,实际生产时,数据回滚时间不会取的这么精确)
4. 数据删除之后,可能表中的数据发生改变,这里演示为,已经插入一行记录:
5. 现在我们想要把数据回退到删除之前的那个版本,进行闪回查询:
select * from student as of timestamp to_timestamp('2019/3/28 12:58:30','yyyy-mm-dd hh24:mi:ss');
此时我们可以查询到删除之前版本的数据。
6. 创建一张临时表,将闪回查询的数据放到临时表当中:
create table student0328 as (
select * from student as of timestamp to_timestamp('2019/3/28 12:58:30','yyyy-mm-dd hh24:mi:ss')
);
7.将临时表当中的数据拷贝到原表中:
1. 将原表中现有数据清空:truncate table student;
2. 将临时表中的数据插入到原表中:insert into student (select a.* from student0328 a);
8.删除临时表
1.先删除表数据:truncate table student0328;
2.再删除表:drop table student0328;
此时,将数据恢复到指定时间版本的工作就做完了。关于为什么删除临时表要先删除数据再drop下一篇博文再介绍。若文章有什么错误之处,还望指出。