Flashback Table的一个案例

来源:互联网 发布:windows 查看显卡切换 编辑:程序博客网 时间:2024/06/05 19:11
 

SQL> conn sys/sysadmin@keymen as sysdba;
已连接。
SQL> create table mytest as select * from hr.departments;

表已创建。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        27

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
     825726

SQL>

SQL> insert into mytest
  2  select * from hr.departments;

已创建27行。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        54

SQL> commit;

提交完成。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        54

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
     825777

SQL>

SQL> flashback table mytest to scn 825726;
flashback table mytest to scn 825726
                *
第 1 行出现错误:
ORA-08185: 用户 SYS 不支持闪回


SQL>

*************************************************************************************************************************

 当某一个用户执行FLASHBACK TABLE时,给予SCN号进行闪回操作时,出项“ORA-08189: 因为未启用行移动功能, 不能闪回表”错误的解决
方法:


SQL> flashback table mytest to scn 825855;
flashback table mytest to scn 825855
                *
第 1 行出现错误:
ORA-08189: 因为未启用行移动功能, 不能闪回表


SQL>
*************************************************************************************************************************
SQL> conn hr/hr@keymen;
已连接。
SQL> create table mytest as select * from hr.departments;

表已创建。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        27

SQL> select current_scn from v$database;
select current_scn from v$database
                        *
第 1 行出现错误:
ORA-00942: 表或视图不存在


SQL> insert into mytest
  2  select * from hr.departments;

已创建27行。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        54

SQL> commit;

提交完成。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        54

SQL> select current_scn from v$database;
select current_scn from v$database
                        *
第 1 行出现错误:
ORA-00942: 表或视图不存在


SQL> flashback table mytest to scn 825855;
flashback table mytest to scn 825855
                *
第 1 行出现错误:
ORA-08189: 因为未启用行移动功能, 不能闪回表


SQL>


************************************************************************************************************************
问题解决如下:

alter table mytest enable row movement;

************************************************************************************************************************
SQL> create table mytest as select * from hr.departments;

表已创建。

SQL> alter table mytest enable row movement;

表已更改。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        27

SQL> select current_scn from v$database;
select current_scn from v$database
                        *
第 1 行出现错误:
ORA-00942: 表或视图不存在


SQL> insert into mytest
  2  select * from hr.departments;

已创建27行。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        54

SQL> commit;

提交完成。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        54

SQL> flashback table mytest to scn 826108;

闪回完成。

SQL> select count(*) from mytest;

  COUNT(*)
----------
        27

SQL>

发现已经将后来插入的数据去掉了,数据表中又仅仅有27行数据,OK!