sqlplus本地登录报错ORA-12545

在客户服务器上尝试登录数据库是碰到错误。
步骤如下:

> sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production ON Thu Nov 17 17:24:16 2011
Copyright (c) 1982, 2005, Oracle. ALL rights reserved.
SQL> conn / AS sysdba
ERROR:
ORA-12545: CONNECT failed because target host OR object does NOT exist
SQL> conn USER/password
ERROR:
ORA-12545: CONNECT failed because target host OR object does NOT exist
SQL> conn USER/password@100.300.100.200/db
Connected.

尝试连接本地的数据库,结果出现了ORA-12545错误,尝试通过网络方式连接,反而没有碰到问题。这说明数据库本身是正常的,而本地无法连接,显示是本地设置出现了问题。
检查了环境变量的设置,包括ORACLE_SID、ORACLE_HOME和PATH,都未发现任何异常,再次尝试连接数据库:

> sqlplus USER/password@100.300.100.200/db
SQL*Plus: Release 10.2.0.1.0 - Production ON Thu Nov 17 17:26:54 2011
Copyright (c) 1982, 2005, Oracle. ALL rights reserved.
 
Connected TO:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
WITH the Partitioning, OLAP AND Oracle DATA Mining options
JServer Release 9.2.0.4.0 - Production
SQL> exit 
Disconnected FROM Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
WITH the Partitioning, OLAP AND Oracle DATA Mining options
JServer Release 9.2.0.4.0 - Production

这次同样连接到数据库,但是由于连接方式和第一次的不同,通过Oracle提示的信息找到了错误的原因。
首先尝试的简易连接方式是10g的新特性,而且从sqlplus的工具版本信息也可以看得出,sqlplus是10.2.0.1版本的。而连接到数据库后显示的数据库服务器版本信息却是9.2.0.4。
显然当前是通过一个10.2的sqlplus客户端,连接到9.2的数据库。那么无论ORACLE_HOME还是PATH都是指向10.2的客户端的,这就是为什么出现ORA-12545错误的原因:

[DEV]dev:/app/oracle/product
> export ORACLE_HOME=/app/oracle/product/920
[DEV]dev:/app/oracle/product
> export PATH=$ORACLE_HOME/bin:$PATH
[DEV]dev:/app/oracle/product
> sqlplus '/ as sysdba'
SQL*Plus: Release 9.2.0.4.0 - Production ON Thu Nov 17 17:28:41 2011
Copyright (c) 1982, 2002, Oracle Corporation. ALL rights reserved.
 
Connected TO:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
WITH the Partitioning, OLAP AND Oracle DATA Mining options
JServer Release 9.2.0.4.0 - Production
SQL>

定位问题的原因,解决就很简单了,设置ORACLE_HOME和PATH到9.2对应的目录后,在本地sqlplus成功连接数据库。

This entry was posted in ORACLE and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *