共计 3845 个字符,预计需要花费 10 分钟才能阅读完成。
丸趣 TV 小编给大家分享一下数据库中闪回有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
闪回主要有闪回表、闪回查询、闪回数据库 (数据来自闪回日志) 三种,这里主要了解闪回表和闪回查询
闪回表:又分以下 2 种:
Flashback table tablename to before drop(数据来自回收站)
Flashback table tablename to scn/timestamp(数据来自 UNDO,必须开启 Row movement)
闪回查询:又分以下 3 种
闪回查询 AS OF SCN/TIMESTAMP(数据来自 UNDO)
闪回版本查询 Flashback Version Query(数据来自 UNDO)
闪回事务查询 Flashback Transaction Query(数据来自 UNDO)
闪回表中关于 Row movement 和 Recyclebin 的知识点
The row_movement_clause lets you specify whether the database can move a table row. Specify ENABLE to allow the database to move a row, thus changing the rowid.
Row movement must be enabled for all tables in the Flashback list unless you are flashing back the table TO BEFORE DROP. That operation is called a flashback drop operation, and it uses dropped data in the recycle bin rather than undo data.
row_movement_clause 允许您指定数据库是否可以移动表行。指定 ENABLE 以允许数据库移动一行,从而更改 rowid。
闪回必须开启行移动,但是闪回 DROP 不需要开启 Row movement,且数据来自回收站
Flashback table 后不需要提交,直接就自动提交了
Flashback table user_tables.TABLE_NAME to before drop(user_tables.TABLE_NAME 就是 recyclebin.ORIGINAL_NAME)
Flashback table recyclebin.OBJECT_NAME to before drop(当一个 table 删除两次时,可以指定回收站里名称按顺序指定回收哪次删除的表)
Flashback table TABLE_NAME to before drop rename to TABLE_NAME2(当删除一个表后,又建立了一张同名表时,可以使用 rename to 恢复成其他名称的表)
Purge recyclebin 只是清空当前用户的回收站
Purge dba_recyclebin 清空所有用户的回收站
闪回表、闪回查询的一个示例
SQL create table hr.test1(id number primary key,name varchar2(10));
Table created.
SQL begin
2 insert into test1 values(1, A
3 insert into test1 values(2, B
4 insert into test1 values(3, C
5 commit;
6 dbms_lock.sleep(5);
7 update test1 set name= C-1 where id=3;
8 insert into test1 values(4, D
9 commit;
10 end;
11 /
PL/SQL procedure successfully completed.
– 闪回版本查询
SQL select versions_startscn,versions_endscn,versions_xid,versions_operation,name from test1 versions BETWEEN SCN MINVALUE AND MAXVALUE;
VERSIONS_STARTSCN VERSIONS_ENDSCN VERSIONS_XID VE NAME
—————– ————— —————- — ——————–
4083242 03002000610D0000 I D
4083242 03002000610D0000 U C-1
4083235 4083242 01000400970C0000 I C
4083235 01000400970C0000 I B
4083235 01000400970C0000 I A
– 闪回查询 AS OF SCN
SQL select * from test1 as of scn 4083235;
ID NAME
———- ——————–
1 A
2 B
3 C
– 闪回版本查询
SQL select versions_startscn,versions_endscn,versions_xid,versions_operation,name from test1 versions BETWEEN TIMESTAMP TO_TIMESTAMP(2017-08-16 14:17:10 , YYYY-MM-DD HH24:MI:SS) AND TO_TIMESTAMP(2017-08-16 14:19:26 , YYYY-MM-DD HH24:MI:SS
VERSIONS_STARTSCN VERSIONS_ENDSCN VERSIONS_XID VE NAME
—————– ————— —————- — ——————–
4083242 03002000610D0000 I D
4083242 03002000610D0000 U C-1
4083235 4083242 01000400970C0000 I C
4083235 01000400970C0000 I B
4083235 01000400970C0000 I A
– 闪回查询 AS OF TIMESTAMP
SQL select * from test1 AS OF TIMESTAMP TO_TIMESTAMP(2017-08-16 14:17:16 , YYYY-MM-DD HH24:MI:SS
ID NAME
———- ——————–
1 A
2 B
3 C
– 闪回事务查询
SQL SELECT undo_sql FROM flashback_transaction_query WHERE xid = HEXTORAW(03002000610D0000
UNDO_SQL
——————————————————————————–
delete from HR . TEST1 where ROWID = AAAWV2AAEAAAAJXAAD
update HR . TEST1 set NAME = C where ROWID = AAAWV2AAEAAAAJXAAC
SQL select * from test1;
ID NAME
———- ——————–
1 A
2 B
3 C-1
4 D
– 启用 ROW MOVEMENT
SQL ALTER TABLE test1 ENABLE ROW MOVEMENT;
Table altered.
–Flashback table to SCN
SQL flashback table test1 to scn 4083235;
Flashback complete.
SQL select * from test1;
ID NAME
———- ——————–
1 A
2 B
3 C
SQL drop table test1;
Table dropped.
–Flashback table to BEFORE DROP
SQL FLASHBACK TABLE test1 TO BEFORE DROP;
Flashback complete.
SQL drop table test1;
Table dropped.
–Flashback table to BEFORE DROP RENAME
SQL FLASHBACK TABLE test1 TO BEFORE DROP RENAME TO test1_2017;
Flashback complete.
SQL select * from test1_2017;
ID NAME
———- ——————–
1 A
2 B
3 C
以上是“数据库中闪回有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!