关于Oracle 10g 中的Recylebin,有两篇文章说得很详细,
(1) Flashback Table by Arup Nanda
(2) Using Oracle's recycle bin by Natalka Roshak
本篇blog只是简单介绍如何去追溯recyclebin的本质。
Recyclebin是Oracle 10g中新加入的一个feature, 就像Windows操作系统提供的回收站一样,删除的东西(如果不是直接删除)都会先放到回收站里,之后我们可以把recycle bin中的东西restore出来。
这有助于解决有时候我们错误把一个表删除的问题,只要该表还存在recyclebin中,我们就可以很容易把它恢复出来,而不需要做很多的工作。这就是之前提到的Oracle 10g 增加的Flashback Table / Flashback Drop。
先看一个测试用例,创建一个表test_for_recyclebin, 插入一条记录,然后commit, 接下来drop该表,
scott@ORCL> create table test_for_recyclebin(version varchar2(20));
Table created.
scott@ORCL> insert into test_for_recyclebin values('Version 1');
1 row created.
scott@ORCL> commit;
Commit complete.
scott@ORCL> drop table test_for_recyclebin;
Table dropped.
scott@ORCL> select * from test_for_recyclebin;
select * from test_for_recyclebin
*
ERROR at line 1:
ORA-00942: table or view does not exist
scott@ORCL> show recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_FOR_RECYCLE BIN$AjbtchOeRHiyRuwIoMqixA==$0 TABLE 2010-01-07:21:13:53
BIN
scott@ORCL> select * from "BIN$AjbtchOeRHiyRuwIoMqixA==$0";
VERSION
--------------------
Version 1
scott@ORCL> flashback table test_for_recyclebin to before drop;
Flashback complete.
scott@ORCL> select * from test_for_recyclebin;
VERSION
--------------------
Version 1