用Instant Client,不安装oracle客户端使用sqlplus连接远程数据库

一、软件下载及环境配置


1.软件下载


到http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html下载如下三个包:
instantclient-basic-win32-10.2.0.4.zip
instantclient-jdbc-win32-10.2.0.4.zip
instantclient-sqlplus-win32-10.2.0.4.zip
将这三个包分别解压,然后内容放到C:/instantclient_10_2下其实一般情况下只需要

instantclient-basic-win32-10.2.0.4.zip这个包就可以

然后从一台安装了oem的机器上复制%ORACLE_HOME/network/admin/tnsnames.ora也放到C:/instantclient_10_2中

 

2.环境变量的设置


在PATH中增加;C:/instantclient_10_2;
新建SQLPATH,LOCAL,TNS_ADMIN,LD_LIBRARY_PATH四个环境变量名,变量值均为C:/instantclient_10_2;
如果查询结果为乱码,设置set NLS_LANG=XXXX(例如SIMPLIFIED CHINESE_CHINA.ZHS16GBK)

 

3. 如果启动SQLPLUS时出现下面的错误:


ORA-12545: Connect failed because target host or object does not exist
试着把tnsnames.ora 中的host 改成IP地址。

 

二、运行


运行cmd
c:>sqlplus log
SQL:>conn system/oracle@orc10g
这样就已经能连接远程服务器了
也可以这么连接:
conn system/oracle@//192.168.1.179:1521/orc10g连接
C:/instantclient_10_2>sqlplus log
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 27 14:45:51 2008Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
SQL> conn system/oracle@//192.168.1.179:1521/orc10g
Connected.
下面看一下ociuldr应用的方法:
C:/instantclient_10_2>ociuldr user=system/oracle@orc10g query="select username from dba_users" file=dba_users.txt
1550 bytes allocated for column USERNAME (1)
0 rows exported at 2008-11-27 14:49:44
29 rows exported at 2008-11-27 14:49:44
output file dba_users.txt closed at 29 rows.
这样查询结果就输出到dba_user.txt文件里面了。
配置tnsnames.ora和sqlnet.ora.。如果本机找不到示例文件,就从其他装有oracle的机器上拷一个。
我拷贝了10g和9i版本下各一份:

10g下tnsnames.ora内容


# tnsnames.ora Network Configuration File: C:/oracle/product/10.1.0/Db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORC10G =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = database007)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orc10g)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)

10g下sqlnet.ora的内容


# sqlnet.ora Network Configuration File: C:/oracle/product/10.1.0/Db_1/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

9i版本下的内容


# TNSNAMES.ORA Network Configuration File: d:/oracle/ora92/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORA9I_192.168.2.206 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.206)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ora9i)
(SERVER = DEDICATED)
)
)
WS_192.168.1.101 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ws)
(SERVER = DEDICATED)
)
)
ORA9I_192.168.2.50 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.50)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ora9i)
(SERVER = DEDICATED)
)
)

9下sqlnet.ora的内容


# SQLNET.ORA Network Configuration File: d:/oracle/ora92/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)

你可能感兴趣的:(用Instant Client,不安装oracle客户端使用sqlplus连接远程数据库)