用Instant Client,不安裝oracle用戶端使用sqlplus串連遠端資料庫
來源:互聯網
上載者:User
一、軟體下載及環境配置1.軟體下載到http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html 下載如下三個包:現地址為:http://www.oracle.com/technetwork/topics/winsoft-085727.htmlinstantclient-basic-win32-10.2.0.4.zipinstantclient-jdbc-win32-10.2.0.4.zipinstantclient-sqlplus-win32-10.2.0.4.zip將這三個包分別解壓,然後內容放到C:\instantclient_10_2下然後從一台安裝了oem的機器上複製%ORACLE_HOME\network\admin\tnsnames.ora也放到C:\instantclient_10_2中從http://www.anysql.net/software/ociuldr.zip下載coiuldr.zip,解壓后里面有windows,linux,solaris三個版本,將ociuldr.exe 複製到C:\instantclient_10_2,其中ociuldr.exe 是一個文本匯出工具,具體參數可以參考http://www.anysql.net/ociuldr.html介紹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. 如果開發JAVA應用程式,還要配置一些環境變數,例如CLASSPATH,JAVA_HOME等等. CLASSES12.jar 檔案是必須的,其他的根據需要添加.4. 如果啟動SQLPLUS時出現下面的錯誤:ORA-12545: Connect failed because target host or object does not exist試著把tnsnames.ora 中的host 改成IP地址。二、運行運行cmdc:>sqlplus /nologSQL:>conn system/oracle@orc10g這樣就已經能串連遠程伺服器了也可以這麼串連:conn system/oracle@//192.168.1.179:1521/orc10g串連C:\instantclient_10_2>sqlplus /nologSQL*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/orc10gConnected. 下面看一下ociuldr應用的方法:C:\instantclient_10_2>ociuldr user=system/oracle@orc10g query="select username from dba_users" file=dba_users.txt1550 bytes allocated for column USERNAME (1)0 rows exported at 2008-11-27 14:49:4429 rows exported at 2008-11-27 14:49:44output 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)