博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用Instant Client,不安装oracle客户端使用sqlplus连接远程数据库
阅读量:6390 次
发布时间:2019-06-23

本文共 3120 字,大约阅读时间需要 10 分钟。

  hot3.png

一、软件下载及环境配置

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)

转载于:https://my.oschina.net/mayude/blog/498112

你可能感兴趣的文章
java计算开方
查看>>
让你不再害怕指针(一)
查看>>
JavaMelody应用监控使用指南
查看>>
我的MYSQL学习心得(六) 函数
查看>>
Swift开发:仿Clear手势操作(拖拽、划动、捏合)UITableView
查看>>
electron版本的串口调度助手
查看>>
使用 jetty-maven-plugin发布maven项目
查看>>
python经典问题在stack overflow上的回答
查看>>
osg 改变模型贴图
查看>>
Web图形开发,SVG还是VML?
查看>>
较全的jdom使用教程
查看>>
并发基础(一):Executor
查看>>
关于autorelease pool一个较好的理解
查看>>
goaccess在定时任务中不执行的问题
查看>>
Flex警告:framework.swc”具有默认样式并且在 library-path 中,表...
查看>>
2.easyui 控件取值方式
查看>>
链表的创建和遍历
查看>>
codewars047: 街头霸王2
查看>>
oc 自定义导航栏背景
查看>>
electron 利用 electron-builder实现自动更新
查看>>