欢迎来到我的地盘:今天是

若得山花插满头,莫问奴归处!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在ORACLE 10g中引入了RECYCLE BIN这个东东,好处就是当你删除了一张表或索引什么的后并不是完全删除,就像WINDOWS中的回收站一样,好处就是防止误删除,可以对误删除的表进行恢复,当然也可以清空RECYCLE BIN。

介绍下RECYCLEBIN里一些简单的东西

先建立一张表,名FOO

SQL>CREATE TALBE FOO(ID NUMBER(5),NAME VARCHAR2(5));

查看当前SCHEME下的所有表的名字

SQL>SELECT TALBE_NAMES FROM USER_TALBES;

TABLE_NAME
------------------------------
FOO

删除表FOO

SQL>DROP TALBE FOO;
SQL>SELECT TALBE_NAMES FROM USER_TALBES;

TABLE_NAME
------------------------------
BIN$Z2ptJ6PcRk6mJbM/0BmmAg==$0

--如果只想看RECYCLEBIN内的表名,可以用 SELECT OBJECT_NAME FROM USER_RECYCLEBIN;效果同上显示

发现有一个名为'BIN$Z2ptJ6PcRk6mJbM/0BmmAg==$0'的表,这个表就是FOO表DROP掉以后在RECYCLE BIN内产生的表,RECYCLE BIN会以特殊的方法来保证每张被删除的表在RECYCLE BIN内的表名都不一样,即使在未被删除时表名是相同的。

如果想看被删除表的详细点的内容,可用
SQL>SHOW RECYCLEBIN;  --这句在SQL*PLUS内可用,但PL/SQL DEV中显示不出内容,不知道怎么会事
或着
SQL>SELECT ORIGINAL_NAME,OBJECT_NAME,TYPE,DROPTIME FROM USER_RECYCLEBIN;

ORIGINAL_NAME                    OBJECT_NAME                    TYPE                      DROPTIME
-------------------------------- ------------------------------ ------------------------- -------------------
FOO                              BIN$Z2ptJ6PcRk6mJbM/0BmmAg==$0 TABLE                     2007-11-18:21:53:02


也可以用
SQL>DESC "BIN$Z2ptJ6PcRk6mJbM/0BmmAg==$0";  --来看被删除表的结构,注意要双引号!!这一句
          
PL/SQL DEV中也不能用,会显示没有这个表,在SQL*PLUS中可用。
 
现在对删除后表名的命名简单说一下:
当一个表被删除并移动到"回收站"中,它的名字要进行一些转换。这样的目的显而易见是为了避免同类对象名称的重复。(这一点和Windows操作系统的回收站不同,Windows中的回收站经过了特殊的处理,操作系统文件可以重名。)
转换后的名字格式如下:
BIN$unique_id$version 其中BIN代表RecycleBin
unique_id是数据库中该对象的唯一标志,26个字符长度
version表示该对象的版本号


删除recyclebin中的对象

我们用PURGE,语句PURGE TABLE "TABLE_NAME";
注:双引不要忘记,对RECYCLEBIN中对象操作都要有" "。

如上例,则:
SQL>purge table "BIN$6qAKR9ljQo+l+1gDCV8xCQ==$0";

SQL>PURGE RECYCLEBIN; --可以清空RECYCLEBIN;


恢复recyclebin中的对象

我们用FLASHBACK,中文名"闪回"
语句FLASHBACK TABLE [已删除TABLE名|"RECYCLEBIN中的名字"] TO BEFORE DROP;

如上例,则:
SQL>FLASHBACK TABLE FOO TO BEFORE DROP;
闪回完成。

但当你在RECYCLEBIN内有2张相同名字的表时候,只有通过
"RECYCLEBIN中的名字"来闪回指定的表,用上面方法只闪回第一个被删除的同名表。

http://blog.chinaunix.net/space.php?uid=8824503&do=blog&cuid=425448

 

 

Oracle10中增加的回收站的功能:

 

1.查看所有与回收站有关的数据对象:

SQL> SELECT T.OWNER,T.OBJECT_NAME,T.OBJECT_TYPE FROM ALL_OBJECTS T WHERE T.OBJECT_NAME LIKE '%RECYCLE%';

 

OWNER                          OBJECT_NAME                    OBJECT_TYPE

------------------------------ ------------------------------ -------------------

SYS                            RECYCLEBIN$                    TABLE

SYS                            RECYCLEBIN$_OBJ                INDEX

SYS                            RECYCLEBIN$_TS                 INDEX

SYS                           RECYCLEBIN$_OWNER              INDEX

SYS                            USER_RECYCLEBIN                VIEW

PUBLIC                         USER_RECYCLEBIN                SYNONYM

PUBLIC                         RECYCLEBIN                     SYNONYM

SYS                            DBA_RECYCLEBIN                 VIEW

PUBLIC                         DBA_RECYCLEBIN                 SYNONYM

 

2.查看回收站的东西:

SQL> SHOW RECYCLEBIN

仅仅列出OBJECT_NAME,ORIGINAL_NAME,TYPE,DROPTIME四列。

ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE DROP TIME

---------------- ------------------------------ ------------ -------------------

A                BIN$R+MY75CQQr+U9AGzM0MJ1Q==$0 TABLE        2009-01-10:16:02:35

B                BIN$tnTJEnUFSiOVfgMGQJD4NA==$0 TABLE        2009-01-10:16:02:44

C1               BIN$V+zsHnmGSLe0aaG+UOkWIw==$0 TABLE        2009-01-10:16:02:54

STUDENT          BIN$zV1QAvZLRF6QUJk1kd9MBg==$0 TABLE        2008-12-28:17:31:20

T                BIN$0Xc7bFJlQlOhoAan/bp4Fw==$0 TABLE        2008-12-14:19:42:19

T2               BIN$WuDMiaqgRraE4AwfZyKR1w==$0 TABLE        2009-01-10:16:03:22

 

3.查看recycle视图的定义

SQL> DESC RECYCLEBIN

Name           Type         Nullable Default Comments                                                

-------------- ------------ -------- ------- --------------------------------------------------------

OBJECT_NAME    VARCHAR2(30)                  New name of the object                                  

ORIGINAL_NAME VARCHAR2(32) Y                Original name of the object                             

OPERATION      VARCHAR2(9) Y                Operation carried out on the object                     

TYPE           VARCHAR2(25) Y                Type of the object                                      

TS_NAME       VARCHAR2(30) Y                Tablespace Name to which object belongs                 

CREATETIME     VARCHAR2(19) Y                Timestamp for the creating of the object                

DROPTIME       VARCHAR2(19) Y                Timestamp for the dropping of the object                

DROPSCN        NUMBER       Y                SCN of the transaction which moved object to Recycle Bin

PARTITION_NAME VARCHAR2(32) Y                Partition Name which was dropped                        

CAN_UNDROP     VARCHAR2(3) Y                User can undrop this object                             

CAN_PURGE      VARCHAR2(3) Y                User can undrop this object                             

RELATED        NUMBER                        Parent objects Obj#                                     

BASE_OBJECT    NUMBER                        Base objects Obj#                                       

PURGE_OBJECT   NUMBER                        Obj# for object which gets purged                       

SPACE          NUMBER       Y                Number of blocks used by this object    

 

4.详细查看具体的

SQL> SELECT T.OBJECT_NAME,T.ORIGINAL_NAME,T.TYPE,T.DROPTIME,T.CREATETIME FROM RECYCLEBIN T;

 

OBJECT_NAME                    ORIGINAL_NAME                    TYPE                      DROPTIME            CREATETIME

------------------------------ -------------------------------- ------------------------- ------------------- -------------------

BIN$0Xc7bFJlQlOhoAan/bp4Fw==$0 T                                TABLE                     2008-12-14:19:42:19 2008-10-11:23:01:11

BIN$ccbejyZCQ4udSL2iQk83Ww==$0 PK_STUDENT_ID                    INDEX                     2008-12-28:17:31:19 2008-12-28:17:27:21

BIN$UyiSWkrGRRSYCbZ4w97ptg==$0 T_TRIGGER                        TRIGGER                   2008-12-14:19:42:19 2008-10-26:15:37:14

BIN$zV1QAvZLRF6QUJk1kd9MBg==$0 STUDENT                          TABLE                     2008-12-28:17:31:20 2008-12-28:17:27:20

BIN$R+MY75CQQr+U9AGzM0MJ1Q==$0 A                                TABLE                     2009-01-10:16:02:35 2008-10-30:22:01:26

BIN$tnTJEnUFSiOVfgMGQJD4NA==$0 B                                TABLE                     2009-01-10:16:02:44 2008-10-30:22:03:44

BIN$V+zsHnmGSLe0aaG+UOkWIw==$0 C1                               TABLE                     2009-01-10:16:02:54 2008-10-26:16:05:42

BIN$WuDMiaqgRraE4AwfZyKR1w==$0 T2                               TABLE                     2009-01-10:16:03:22 2008-10-26:15:36:19

BIN$aFjB3kaNQmacc1irUBJfsg==$0 TT_TRIGGER                       TRIGGER                   2009-01-10:16:03:22 2008-10-26:15:39:22

BIN$4I6nffFIQjeGv3jKsc4Xow==$0 T3                               TABLE                     2009-01-10:16:03:22 2008-10-26:15:38:45

BIN$9gb8zixHSGqKGH96Te1/gQ==$0 TEST                             TABLE                     2009-01-10:16:03:22 2008-10-12:21:21:46

BIN$DxduMzI4RdqPL/UFxOJe+w==$0 TEST1                            TABLE                     2009-01-10:16:03:22 2008-10-12:21:23:37

BIN$egeKA5GkThWaiHe/0GixPQ==$0 TEST2                            TABLE                     2009-01-10:16:03:22 2008-10-12:21:28:39

BIN$GXH7XLqTQTGbjwzzlrNt6g==$0 TEST3                            TABLE                     2009-01-10:16:03:22 2008-10-12:21:49:29

BIN$Gouz6KxTS+2ac55DqAYJiQ==$0 TEST4                            TABLE                     2009-01-10:16:03:22 2008-10-12:22:11:55

BIN$Sg1vjzx0TIW3m9lmCWMqQg==$0 TEST5                            TABLE                     2009-01-10:16:03:22 2008-10-12:22:13:34

BIN$7IuwzwIER2ew1nm0j7jSTw==$0 TEST6                            TABLE                     2009-01-10:16:03:22 2008-10-15:22:03:39

BIN$UuoORCOETPCYuEY7indiSg==$0 TT                               TABLE                     2009-01-10:16:03:22 2008-10-26:16:10:49

BIN$n9q6RusoSlmfbRngZftmPA==$0 TT3                             TABLE                     2009-01-10:16:03:23 2008-10-29:21:07:25

 

5.清除一个表:

SQL> PURGE TABLE "BIN$UuoORCOETPCYuEY7indiSg==$0";

 

Done

 

6.清除回收站:

SQL> PURGE RECYCLEBIN;

 

Done

 

SQL> SELECT T.OBJECT_NAME,T.ORIGINAL_NAME,T.TYPE,T.DROPTIME,T.CREATETIME FROM RECYCLEBIN T;

 

OBJECT_NAME                    ORIGINAL_NAME                    TYPE                      DROPTIME            CREATETIME

------------------------------ -------------------------------- ------------------------- ------------------- -------------------

 

 

6.恢复一个表:

SQL> DROP TABLE P1;

 

Table dropped

 

SQL> SELECT T.OBJECT_NAME,T.ORIGINAL_NAME,T.TYPE,T.DROPTIME,T.CREATETIME FROM RECYCLEBIN T;

 

OBJECT_NAME                    ORIGINAL_NAME                    TYPE                      DROPTIME            CREATETIME

------------------------------ -------------------------------- ------------------------- ------------------- -------------------

BIN$wtP8UH7PSFqRKd5NzdUsgQ==$0 SYS_C005204                      INDEX                     2009-01-11:15:54:22 2008-10-26:16:04:26

BIN$vaxMSW3YT/mOkJTp9VmtDw==$0 P1                               TABLE                     2009-01-11:15:54:22 2008-10-26:16:04:26

 

SQL> FLASHBACK TABLE P1 TO BEFORE DROP;

 

Done

SQL> SELECT * FROM TAB WHERE TNAME ='P1';

 

TNAME                          TABTYPE CLUSTERID

------------------------------ ------- ----------

P1                             TABLE  

 

7.不启用回收站:

SQL> ALTER SESSION SET RECYCLEBIN=OFF;

Session altered

 

SQL> PURGE RECYCLEBIN;

Done

 

SQL> DROP TABLE P1;

Table dropped

 

SQL> SELECT T.OBJECT_NAME,T.ORIGINAL_NAME,T.TYPE,T.DROPTIME,T.CREATETIME FROM RECYCLEBIN T;

OBJECT_NAME                    ORIGINAL_NAME                    TYPE                      DROPTIME            CREATETIME

------------------------------ -------------------------------- ------------------------- ------------------- -------------------

 

8.设置启用或关闭回收站

SQL> ALTER SYSTEM SET RECYCLEBIN=OFF;

 

System altered

 

SQL> ALTER SYSTEM SET RECYCLEBIN=ON;

 

System altered

 

SQL> ALTER SESSION SET RECYCLEBIN=ON;

 

Session altered

 

posted on 2011-09-19 14:30  莫问奴归处  阅读(6530)  评论(0编辑  收藏  举报
轩轩娃