oracle10g的undrop功能一點實踐

tolywang發表於2007-07-09
 看到oracle10g有防止表誤刪除的特點,我自己就小試了一把,
  下面是我的操作過程:
  bash-2.05$ sqlplus scott/tiger
  
  SQL*Plus: Release 10.1.0.0.0 - Beta on Mon Aug 18 16:50:18 2003
  
  Copyright (c) 1982, 2003, Oracle Corporation. All rights reserved.

  Connected to:
  Oracle10i Enterprise Edition Release 10.1.0.0.0 - Beta
  With the Partitioning and Oracle Data Mining options
  
  SQL> select * from tab;
  
  TNAME TABTYPE CLUSTERID
  ------------------------------
  BONUS TABLE
  DUMMY TABLE
  EMP TABLE
  EMP2 TABLE
  SALGRADE TABLE
  T TABLE
  
  6 rows selected.
  
  SQL> desc emp2;
  Name Null? Type
  ------------------------------
  EMPNO NOT NULL NUMBER(4)
  ENAME VARCHAR2(10)
  JOB VARCHAR2(9)
  MGR NUMBER(4)
  HIREDATE DATE
  SAL NUMBER(7,2)
  COMM NUMBER(7,2)
  DEPTNO NUMBER(2)
  
  SQL> select * from emp2; so.2168.net網管資料庫任你搜
  
  EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
  ---------- ---------- --------- -----
  7369 SMITH CLERK 7902 17-DEC-80 800 20
  7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
  7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
  
  SQL> drop table emp2;
  
  Table dropped.
  
  SQL> select * from emp2;   
  select * from emp2
  *
  ERROR at line 1:
  ORA-00942: table or view does not exist
  
  SQL> select * from tab;
  
  TNAME TABTYPE CLUSTERID
  -----------------------------
  BONUS TABLE
  DUMMY TABLE
  EMP TABLE
  RB$$8074$TABLE$0 TABLE(oracle在recycle bin裡面生成的物件,就是emp2的複製)
  SALGRADE TABLE
  T TABLE
  
  6 rows selected.
  
  SQL> desc RB$$8074$TABLE$0;
  Name Null? Type
  ---------------------------
  EMPNO NOT NULL NUMBER(4)
  ENAME VARCHAR2(10)
  JOB VARCHAR2(9)
  MGR NUMBER(4)
  HIREDATE DATE
  SAL NUMBER(7,2) 需要什麼來搜一搜吧so.2168.net
  COMM NUMBER(7,2)
  DEPTNO NUMBER(2)
  
  SQL> select * from RB$$8074$TABLE$0;
  
  EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
  ---------- ---------- --------- ----------
  7369 SMITH CLERK 7902 17-DEC-80 800 20
  7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
  7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
  
  
  SQL> undrop table RB$$8074$TABLE$0;(應該是把表從Recycle Bin中去掉)
  
  Table undropped.
  
  SQL> alter table RB$$8074$TABLE$0 rename to emp2;
  
  Table altered.
  
  SQL> select * from emp2;
  
  EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
  ---------- ---------- --------- ---------- ------
  7369 SMITH CLERK 7902 17-DEC-80 800 20
  7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
  7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
  
  可以看到所有的資料都在,對錶可以執行DDL,DML操作
  SQL> insert into emp2 select * from emp;
  
  14 rows created.
  如果不執行“undrop table RB$$8074$TABLE$0”而直接執行“alter table RB$$8074$TABLE$0 rename to emp2”
  就會有如下問題:
  SQL> insert into emp2 select * from emp;
  insert into emp2 select * from emp
  *
  ERROR at line 1:
  ORA-38301: can not perform DDL/DML over objects in Recycle Bin
  
  如果要刪除Recycle Bin中表可以:
  SQL> purge table RB$$8063$TABLE$0;
  
  Table purged.
  
  這樣這個表就真的刪除了,也就可能再undrop了!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-84746/,如需轉載,請註明出處,否則將追究法律責任。

相關文章