欢迎光临老紫竹的 个人网站 和我在 优快云的博客
1 定义SCN码
SQL> variable SCN number
SQL> exec :scn :=dbms_flashback.get_system_change_number
PL/SQL 过程已成功完成。
2 看看当前的数值
SQL> print scn
SCN
----------
590630
3 看看当前数据情况
SQL> select count(*) from scott.emp;
COUNT(*)
----------
14
4 删除数据
SQL> delete from scott.emp;
已删除14行。
5 查看删除后的数据
SQL> select count(*) from scott.emp;
COUNT(*)
----------
0
6 使用SCN查询历史数据
SQL> select count(*) from scott.emp as of SCN:scn;
COUNT(*)
----------
14
7 提交事务,确认删除操作
SQL> commit;
提交完成。
8 同时查询当前数据和SCN时的数据
SQL> select * from (select count(*) from scott.emp),(select count(*) from scott.
emp as of scn:scn);
COUNT(*) COUNT(*)
---------- ----------
0 14
9 尝试闪回数据
SQL> flashback table scott.emp to scn:scn;
flashback table scott.emp to scn:scn
*
第 1 行出现错误:
ORA-08189: 因为未启用行移动功能, 不能闪回表
10 修改表格,使其允许闪回
SQL> alter table scott.emp enable row movement;
表已更改。
11 闪回操作
SQL> flashback table scott.emp to scn:scn;
闪回完成。
12 确认闪回的数据
SQL> select * from (select count(*) from scott.emp),(select count(*) from scott.
emp as of scn:scn);
COUNT(*) COUNT(*)
---------- ----------
14 14
SQL>
测试完毕,全部成功
欢迎光临老紫竹的 个人网站 和我在 优快云的博客