Oracle 10g引入了recyclebin,类似于windows的回收站,使你能够很方便的恢复误删的表。
但是对于truncate table,好像还是没有一种快速的恢复方法
[@more@]SQL>select object_name,object_type from user_objects
OBJECT_NAME OBJECT_TYPE
------------------------ --------- -------------------
FLASH TABLE
IDX1_FLASH INDEX
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
FLASH TABLE
SQL> drop table flash;
Table dropped.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$NHMSE3qoQlmhlzmeiDOQpw==$0 TABLE
SQL>select object_name,object_type from user_objects
OBJECT_NAME OBJECT_TYPE
--------------------------------------------------------------- -------------------
BIN$NHMSE3qoQlmhlzmeiDOQpw==$0 TABLE
BIN$fJd3Ze8AQJODogj64ZE+7A==$0 INDEX
dropped table FLASH, instead of completely disappearing, was renamed to a system-defined name. It stays in the same tablespace, with the same structure as that of the original table.
The indexes or triggers defined on the table, they are renamed too, using the same naming convention used by the table
The table and its associated objects are placed in a logical container known as the "recycle bin,"
SQL> show recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
-------------------------- ------------------------------------------- ------------------- -------------------
FLASH BIN$NHMSE3qoQlmhlzmeiDOQpw==$0 TABLE 2004-09-08:16:56:11
ORIGINAL NAME: the original name of the table
RECYCLEBIN NAME: the new name in the recycle bin
SQL> flashback table flash to before drop;
Flashback complete.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
FLASH TABLE
SQL>select object_name,object_type from user_objects
OBJECT_NAME OBJECT_TYPE
-------------------------------------------------- -------------------
FLASH TABLE
BIN$fJd3Ze8AQJODogj64ZE+7A==$0 INDEX
SQL>alter index “BIN$fJd3Ze8AQJODogj64ZE+7A==$0” rename to idx1_flash;
SQL> show recyclebin
“EMPTY”
The un-drop feature brings the table back to its original name, but not the associated objects like indexes and triggers, which are left with the recycled names.
SQL>purge recyclebin
SQL> drop table flash purge;
Table dropped.
SQL> show recyclebin
“EMPTY”
SQL>PURGE TABLE TEST;
or using its recycle bin name:
SQL>PURGE TABLE "BIN$04LhcpndanfgMAAAAAANPw==$0";
SQL> drop table flash;
Table dropped.
SQL>select object_name,object_type from user_objects
OBJECT_NAME OBJECT_TYPE
--------------------------------------------------------- -------------------
BIN$RGaBIxRdSW65NUWeQ6NOAg==$0 TABLE
BIN$uix7J5C2TomXdYKjdzGXOQ==$0 INDEX
SQL> purge index idx1_flash;
Index purged.
SQL>select object_name,object_type from user_objects
OBJECT_NAME OBJECT_TYPE
--------------------------------------------------------- -------------------
BIN$RGaBIxRdSW65NUWeQ6NOAg==$0 TABLE
PURGE TABLESPACE USERS;
PURGE TABLESPACE USERS USER SCOTT;
A user such as SCOTT would clear his own recycle bin with
PURGE RECYCLEBIN;
You as a DBA can purge all the objects in any tablespace using
PURGE DBA_RECYCLEBIN;
CREATE TABLE TEST (COL1 NUMBER);
INSERT INTO TEST VALUES (1);
COMMIT;
DROP TABLE TEST;
CREATE TABLE TEST (COL1 NUMBER);
INSERT INTO TEST VALUES (2);
COMMIT;
DROP TABLE TEST;
CREATE TABLE TEST (COL1 NUMBER);
INSERT INTO TEST VALUES (3);
COMMIT;
DROP TABLE TEST;
At this point, if you were to flash-back the table TEST, the third version of the table is retrieved, not the first. So the column COL1 will have the value 3, not 1.
you can also retrieve the other versions of the dropped table
SQL>FLASHBACK TABLE TEST TO BEFORE DROP RENAME TO TEST2;
SQL>FLASHBACK TABLE TEST TO BEFORE DROP RENAME TO TEST1;
SQL>FLASHBACK TABLE "BIN$04LhcpnoanfgMAAAAAANPw==$0" TO BEFORE DROP RENAME TO TEST2;
SQL>FLASHBACK TABLE "BIN$04LhcpnqanfgMAAAAAANPw==$0" TO BEFORE DROP RENAME TO TEST1;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/207/viewspace-778638/ ,如需转载,请注明出处,否则将追究法律责任。