针对Recycle Bin对象的操作
已经放到回收站里的表是不能用drop 命令删除的(注意对象名字上的双引号):
SQL> DROP table "BIN$V3f/oYUITrCEF2cotS5JaA==$0"
2 /
DROP table "BIN$V3f/oYUITrCEF2cotS5JaA==$0"
*
ERROR at line 1:
ORA-38301: can not perform DDL/DML over objects in Recycle Bin
SQL>
如果要清掉该对象,使用purge命令:
SQL> PURGE table oreginal_table_name//这里用得表的原名 用"BIN$V3f/oYUITrCEF2cotS5JaA==$0"不行。。。
2 /
Table purged.
SQL> SELECT object_name, original_name FROM user_recyclebin;
OBJECT_NAME ORIGINAL_NAME
------------------------------ ---------------
BIN$VL+ZsqVlQF6R2nYnwAqtvw==$0 FOO
SQL>
对象已经清掉。如果直接清空所有的Recycle Bin中的对象:
SQL> PURGE RECYCLEBIN;
Recyclebin purged.
SQL> SELECT object_name, original_name FROM user_recyclebin;
no rows selected
SQL>
恢复表,用回闪表的功能:
SQL> FLASHBACK TABLE foo TO BEFORE DROP;
Flashback complete.
SQL>SELECT table_name FROM user_tables;
TABLE_NAME
------------------------------------------------------------
FOO
SQL>
注:在10g Beta版本中,使用Undrop命令来做到这一点.
有的时候,可能同一个名字的表被删除到回收站中:
SQL> DROP TABLE FOO;
Table dropped.
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
FOO BIN$lfTbzOjISXaw8u0BIO7pNA==$0 TABLE 2004-10-30:15:18:03
SQL> CREATE TABLE foo AS SELECT * FROM DUAL;
Table created.
SQL> DROP TABLE foo;
Table dropped.
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
FOO BIN$J63QaUaKTmC1glat+imjeg==$0 TABLE 2004-10-30:15:18:50
FOO BIN$lfTbzOjISXaw8u0BIO7pNA==$0 TABLE 2004-10-30:15:18:03
SQL> FLASHBACK TABLE FOO TO BEFORE DROP;
Flashback complete.
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
FOO BIN$lfTbzOjISXaw8u0BIO7pNA==$0 TABLE 2004-10-30:15:18:03
SQL>
默认的恢复是第一个被删除的FOO表。如果要恢复指定的表,可以在FLASHBACK TABLE 后面加上指定的RECYCLEBIN 参数指定其他的名字:
SQL> FLASHBACK TABLE "BIN$lfTbzOjISXaw8u0BIO7pNA==$0" TO BEFORE DROP;
FLASHBACK TABLE "BIN$lfTbzOjISXaw8u0BIO7pNA==$0" TO BEFORE DROP
*
ERROR at line 1:
ORA-38312: original name is used by an existing object
SQL> FLASHBACK TABLE "BIN$lfTbzOjISXaw8u0BIO7pNA==$0" TO BEFORE DROP
2 RENAME TO foo2;
Flashback complete.
SQL>