windows 下
方法是:使用Oracle InstantClient连接oracle数据库
1 下载相应的程序,如是10204的instantclient-basic-win32-10.2.0.4.zip (34,742,358 bytes)
或者instantclient-basic-win32-10.2.0.3-20061115.zip
WIN64位系统
2 将Oracle Instatnt Client解压。如,至D:\test\instantclient_10_2
3 环境变量配置: "控制面板"-"系统"-"高级"-"环境变量"-"系统变量"添加
NLS_LANG = AMERICAN_AMERICA.ZHS16GBK(或SIMPLIFIEDCHINESE_CHINA.ZHS16GBK) TNS_ADMIN = D:\test\instantclient_10_2 LD_LIBRARY_PATH = D:\test\instantclient_10_2 SQLPATH = D:\test\instantclient_10_2 Path变量结尾添加;D:\test\instantclient_10_2 |
4 在D:\test\instantclient_10_2中用添加如下内容的文件,文件名为tnsnames.ora
5 可以下载单独的Oracle SDK 和Oracle SQL PLUS到安装目录中,解压即可运行
附ORA文件内容与格式
tnsnames.ora #D:/instantclient_10_2/tnsname.ora ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.0.47)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = dedicated) (SERVICE_NAME = mydb1) ) ) |
如果执行完以上步骤之后报错:
ORA_12705:Cannot access NLS data files orinvalid environment specified的错误
则执行NLS_LANG = AMERICAN_AMERICA.ZHS16GBK(或SIMPLIFIEDCHINESE_CHINA.ZHS16GBK)
的时候替换另一种字符集
linux下
1、 去官网下载安装包
比如对应11gr2的
oracle-instantclient11.2-basic-11.2.0.1.0-1.i386.rpm oracle-instantclient11.2-devel-11.2.0.1.0-1.i386.rpm oracle-instantclient11.2-sqlplus-11.2.0.1.0-1.i386.rpm |
2、 copy到linux上执行安装
rpm -ivh XXX.rpm
3、 配置环境变量
编辑vi .bashrc,追加
export ORACLE_HOME=/usr/lib/oracle/11.2/client export TNS_ADMIN=$ORACLE_HOME/network/admin export NLS_LANG='simplified chinese_china'.ZHS16GBK export LD_LIBRARY_PATH=$ORACLE_HOME/lib export PATH=$ORACLE_HOME/bin:$PATH |
手动创建目录$ORACLE_HOME/network/admin
并在这个目录下创建编辑文件tnsnames.ora
添加链接串
ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.9.76)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) ) |
4、 执行命令source .bashrc生效修改内容,测试连接sqlplus
5、 如果出现sqlplus: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
则安装相应包即可