闪回须知:

 1 使用闪回表注意如下事项:
 2 
 3 (1)被闪回的表必须启用行移动功能
 4 
 5   SQL> alter table dept enable row movement;
 6 
 7 (2)“FLASHBACK TABLE”命令的执行者必须有“FLASHBACK ANY TABLE”系统权限或者在被闪回的表上具有“FLASHBACK”对象权限。
 8 
 9 (3)“FLASHBACK TABLE”属于DDL命令,隐式提交。
10 
11 (4)SYS用户的任何表无法使用此功能。

  闪回的类型

    1闪回表( Flashback Table)
      将表回滚到一个过去的时间点或系统改变号scn上,用来快速恢复表。

    2闪回删除 ( Flashback Drop)
      将删除的对象从回收站中还原。
  
    3闪回版本查询(Flashback Version Query)
      查著看某个表在指定时间段或某两个scn之间的修改操作。

    4闪叫事务查询( Flashback Transaction Query)
      查看某个对象的事务信息,该信息中记录了撤销sql语句,用于实现对该事务进行撤销处理。

    5闪回数据库(Flashback Database)。
      将数据库前滚到一个过去的时间点或系统改变号scn,快速恢复数据库。

    6闪回数据归档(Flashback Data Archive)。
      将数据库对象的修改操作记录在闪回数据归档区域中,这样可以使得数据的闪回不依赖于UNDO撤销数据。
   

  01,闪回具体时间

   set time on; 开启时间显示

   查看具体时间:

SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

    TO_CHAR(SYSDATE,'YY
    -------------------
    2019-02-21 21:00:02

   以时间的方式生成节点

   开始生成数据
    insert into dg values(11); 

SQL> select * from dg;

	ID
----------
	 1
	 2
	 3
	 4
	 5
	 6
	 7
	 8
	10

 

 再次插入数据

  闪回操作:

SQL>  flashback table dg to timestamp to_timestamp('2019-02-21 20:43:22','yyyy-mm-dd hh24:mi:ss');
 flashback table dg to timestamp to_timestamp('2019-02-21 20:43:22','yyyy-mm-dd hh24:mi:ss')
                 *
ERROR at line 1:
ORA-08185: Flashback not supported for user SYS

   发现默认不能用sys闪回,这个加入必须要的话是可以完成的,现再先不使用

    切换用户 

SQL> show user
USER is "SYS"
SQL> conn scott/123456
Connected.
SQL> show user
USER is "SCOTT"

   重新建表,插入数据查询

SQL> create table dg(id number);

Table created.

SQL> insert into dg values(1);

1 row created.

   再次闪回,

SQL> flashback table dg to timestamp to_timestamp('2019-02-21 20:57:08','yyyy-mm-dd hh24:mi:ss');
flashback table dg to timestamp to_timestamp('2019-02-21 20:57:08','yyyy-mm-dd hh24:mi:ss')
                *
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled

    发现没开启行移

SQL> alter table dg enable row movement;

Table altered.

     这次总行了吧

SQL> flashback table dg to timestamp to_timestamp('2019-02-21 20:57:08','yyyy-mm-dd hh24:mi:ss');

Flashback complete.

     再次查看数据 

SQL> select * from dg;

no rows selected

     我的天闪回有点多

  02,闪回大概时间

flashback table dg to timestamp(systimestamp-interval '10' minute);

   03,闪回SCN

    SCN查询 

01,
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
    1094422

02,
SQL> select dbms_flashback.get_system_change_number() from dual;

DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER()
-----------------------------------------
				  1094447

     flashback table dg to scn 1094422;

  05,多表闪回

flashback table scott.dg,scott.t to scn 1094422

 二,闪回删表

   01,删除表: 

SQL> drop table t
  2  ;

Table dropped.
 1 select * from t
 2               *
 3 ERROR at line 1:
 4 ORA-00942: table or view does not exist
 5 
 6 
 7 SQL> insert into t values(2);
 8 insert into t values(2)
 9             *
10 ERROR at line 1:
11 ORA-00942: table or view does not exist
View Code

相关文章:

  • 2022-01-01
  • 2021-04-25
  • 2021-05-28
  • 2022-01-16
  • 2022-12-23
  • 2021-08-23
  • 2021-04-09
猜你喜欢
  • 2021-10-26
  • 2022-12-23
  • 2021-06-08
  • 2021-10-31
  • 2021-09-17
相关资源
相似解决方案