【問題處理】9i客戶端無法“直接”使用purge recyclebin命令清理10g資料庫回收站資訊

secooler發表於2010-02-03
偶遇9i客戶端在連線10g資料庫時,無法直接使用“purge recyclebin”命令清理回收站資訊的問題。現將問題現象、處理方法及其原因總結在此,供參考。

1.建立測試表T,模擬生成T表DROP後的回收站資訊。
sec@ora10g> create table t (x int);

Table created.

sec@ora10g> select * from cat;

TABLE_NAME                     TABLE_TYPE
------------------------------ ----------------------
T                              TABLE

sec@ora10g> drop table t;

Table dropped.

sec@ora10g> select * from cat;

TABLE_NAME                     TABLE_TYPE
------------------------------ ----------------------
BIN$fq7Ry1Hzz1DgQAB/AQAMLA==$0 TABLE

OK,此時便可得到T表刪除後的殘留資訊(存放在recyclebin中)。

2.再現一下9i客戶端無法刪除10g回收站問題。
C:\>sqlplus sec/sec@ora10g

SQL*Plus: Release 9.2.0.1.0 - Production on Wed Feb 3 16:07:33 2010

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options

SQL> purge recyclebin;
SP2-0734: unknown command beginning "purge recy..." - rest of line ignored.

提示“SP2-0734”錯誤,這個錯誤表示語法不對,使用的命令不存在。
ora10g@secDB /home/oracle$ oerr sp2 734
00734, 0, "unknown command beginning \"%s...\" - rest of line ignored.\n"
// *Cause:  The command entered was invalid.
// *Action: Check the syntax of the command you used for the correct
//          options.

是拼寫錯誤導致的問題?可以肯定,不是這個原因。那是為什麼呢?

3.嘗試使用10g的客戶端完成回收站的清理。“同樣的命令”可以完成回收站清理任務。
C:\>sqlplus sec/sec@ora10g

SQL*Plus: Release 10.2.0.3.0 - Production on Wed Feb 3 16:27:56 2010

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options

sec@ora10g> select * from cat;

TABLE_NAME                     TABLE_TYPE
------------------------------ ----------------------
BIN$fq7Ry1Hzz1DgQAB/AQAMLA==$0 TABLE

sec@ora10g> purge recyclebin;

Recyclebin purged.

sec@ora10g> select * from cat;

no rows selected

4.問題原因分析
仔細思考一下,為什麼同樣的命令在10g客戶端中可以執行,但是在9i客戶端環境下無法使用呢?
其實,根本原因已經浮出水面,“purge recyclebin”在9i的SQL*Plus中並不存在,這個命令是在10g中才被引入。所以在9i的客戶端中是無法直接使用這個命令來完成回收站清理的。

5.問題解決途徑
1)第一種解決方法:升級Oracle客戶端版本,保證客戶端與伺服器端Oracle版本一致。
這是根本解決方法,如果條件允許,客戶端與伺服器端的資料庫版本應保持一致。

2)第二種解決方法:使用PL/SQL塊完成回收站清理
既然直接使用“purge recyclebin”無法完成我們的任務,我們可以迂迴的完成這個任務:在PL/SQL塊中使用“purge recyclebin”命令完成清理。
(1)重新模擬一下drop過程
C:\>sqlplus sec/sec@ora10g

SQL*Plus: Release 9.2.0.1.0 - Production on Wed Feb 3 17:37:34 2010

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options

SQL> create table t (x int);

Table created.

SQL> col table_name for a30
SQL> select * from cat;

TABLE_NAME                     TABLE_TYPE
------------------------------ ----------------------
T                              TABLE

SQL> drop table t;

Table dropped.

SQL> col table_name for a30
SQL> select * from cat;

TABLE_NAME                     TABLE_TYPE
------------------------------ ----------------------
BIN$frAD2zWA6LzgQAB/AQAYJA==$0 TABLE

重新模擬完畢。

(2)直接使用purge recyclebin無法清理回收站。
SQL> purge recyclebin;
SP2-0734: unknown command beginning "purge recy..." - rest of line ignored.

(3)迂迴處理,成功!
SQL> begin
  2     execute immediate 'purge recyclebin';
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select * from cat;

no rows selected

6.小結
為了規避不必要的麻煩和問題,請儘量保證Oracle客戶端版本與伺服器端版本一致。
透過問題現象看本質,發現問題,解決問題,總結經驗。

Good luck.

secooler
10.02.03

-- The End --

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

相關文章