SQL> column value format a10;
SQL>
----------
on
or
sql> alter session set recyclebin = on scope=spfile;
or
sql> alter session set recyclebin = off scope=spfile;
2.查看回收站里的内容
SQL> show recyclebin;
or
SQL> select * from user_recyclebin;
下面将创建的表删除后放入回收站
SQL> show user;
USER is "HXL"
SQL> create table test_rbin(val number);
Table created.
SQL> insert into test_rbin(val) values(10);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> show recyclebin;
ORIGINAL NAME
---------------- ------------------------------ ------------ -------------------
TEST_RBIN
3.从回收站恢复删除的表
可以使用如下语句从回收站恢复删除的表
sql > flashback table <<table_name>> to before drop;
例如我们恢复刚才删除的表
SQL> flashback table test_rbin to before drop;
Flashback complete.
SQL> select * from test_rbin;
----------
在恢复的过程的同时我们可以将表另外命名,命令如下:
sql>flashback table << dropped table name >> to before drop rename to <<new table name >>;
sql>flashback table test_rbin to before drop rename to test_rbin1;
Oracle从回收站恢复是按照"降序"恢复的,比如连续3次删除同样一个表(删除后再创建,再删除),恢复的是先恢复最后一次删除的表.
SQL> show user;
USER is "HXL"
SQL> drop table test_rbin;
Table dropped.
SQL> create table test_rbin (col1 number);
Table created.
SQL> insert into test_rbin values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> create table test_rbin (col1 number);
Table created.
SQL> insert into test_rbin values (2);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> create table test_rbin (col1 number);
Table created.
SQL> insert into test_rbin values (3);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> show recyclebin;
ORIGINAL NAME
---------------- ------------------------------ ------------ -------------------
TEST_RBIN
TEST_RBIN
TEST_RBIN
TEST_RBIN
SQL> select * from test_rbin1;
----------
SQL> select * from test_rbin2;
----------
SQL> select * from test_rbin3;
----------
4.清空回收站
清空某个表,清空表的同时也将该表上的索引和约束都一起清空了的.
SQL
清空索引,保留表数据
SQL > purge
清空表空间
SQL > purge tablespace <<Table Space Name>>;
清空某个用户下的表空间
SQL > purge tablespace <<Table Space Name>> user <<User Name>>;
清空整个回收站
SQL > purge recyclebin;
删除表的同时从回收站中清除
SQL > drop table
说明:
若表上建有索引,在恢复表后,索引也一起恢复了且不会失效,但索引名字不是之前的名字了,而是以BIN$前缀的名 字,这个时候按需要可以命名该索引(alter index "BIN$XXXXX" rename to original_name,注意回收站里的名称需要双引号);
表以及表上的索引和约束,删除会进入到回收站,其他对象如存储过程,包,函数删除后,在回收站是找不到的,可以说回收站只收集删除后的表.
一旦表从回收站清除后,就不能使用FLASHBACK恢复了;
-- The End --