不安裝oracle客戶端使用sqlplus

聽海★藍心夢發表於2012-02-09

一、軟體下載及環境配置
1.軟體下載
下載如下三個包:
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下

然後從一臺安裝了oem的機器上覆制%ORACLE_HOME\network\admin\tnsnames.ora也放到C:\instantclient_10_2中

下載coiuldr.zip,解壓后里面有windows,linux,
solaris三個版本,將ociuldr.exe 複製到C:\instantclient_10_2,其中ociuldr.exe 是一個文字匯出工具,具體引數可以參考
介紹

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地址。

二、執行
執行cmd
c:>sqlplus /nolog
SQL:>conn

這樣就已經能連線遠端伺服器了

也可以這麼連線:
conn
system/oracle@//192.168.1.179:1521/orc10g連線
C:\instantclient_10_2>sqlplus /nolog
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
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)

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/751371/viewspace-715957/,如需轉載,請註明出處,否則將追究法律責任。

相關文章