9i客户端无法“直接”使用purge recyclebin命令清理10g数据库回收站信息

来源:互联网 发布:单片机控制蜂鸣器发声 编辑:程序博客网 时间:2024/04/30 10:48
 偶遇9i客户端在连接10g数据库时,无法直接使用“purgerecyclebin”命令清理回收站信息的问题。现将问题现象、处理方法及其原因总结在此,供参考。

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 --

来源:http://space.itpub.net/519536/viewspace-626767