[時(shí)間]:2009-7-20
[摘要]:使用Oracle Instant Client - SQL*Plus從客戶端連接Oracle服務(wù)器。
[關(guān)鍵字]:SQL*Plus,Instant,Oracle,JDevelopers,PL/SQL
[環(huán)境]:Oracle 11g
[作者]:Winty (wintys@gmail.com) http://www.aygfsteel.com/wintys
[正文]:
1、下載Oracle Instant Client
服務(wù)器系統(tǒng)Windows Server 2003,安裝了Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 ,帶有SQL*Plus??蛻舳讼到y(tǒng)Windows XP SP3,需要使用SQL*Plus對Oracle數(shù)據(jù)庫進(jìn)行操作。搜索了一下,發(fā)現(xiàn)Oracle Instant Client(http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html)正是所需。
如果只使用SQL*Plus,則下載以下兩個(gè)包即可:
a)、Instant Client Package - Basic:
All files required to run OCI, OCCI, and JDBC-OCI applications
instantclient-basic-win32-11.1.0.6.0.zip (43,316,697 bytes)
b)、Instant Client Package - SQL*Plus:
Additional libraries and executable for running SQL*Plus with Instant Client
instantclient-sqlplus-win32-11.1.0.6.0.zip (788,050 bytes)
2、安裝配置
a、將instantclient-basic-win32-11.1.0.6.0.zip 和 instantclient-sqlplus-win32-11.1.0.6.0.zip解壓到同一目錄下(如:F:\Oracle\InstantClient)。
b、環(huán)境變量設(shè)置:
將F:\Oracle\InstantClient增加到系統(tǒng)環(huán)境變量PATH中。
再添加環(huán)境變量TNS_ADMIN (admin目錄是自己新建的):
TNS_ADMIN=F:\Oracle\InstantClient\admin
可選環(huán)境變量:
NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
c、在TNS_ADMIN所指目錄F:\Oracle\InstantClient\admin下增加一個(gè)配置文件tnsnames.ora。這個(gè)文件可以直接從服務(wù)器的Oracle安裝目錄(H:\Oracle\product\11.1.0\db_1\network\admin\tnsnames.ora)下找到,直接復(fù)制過來。
tnsnames.ora:
# tnsnames.ora Network Configuration File:
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.168.1.101)
)
)
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.168.1.101)
)
)
3、使用SQL*Plus:
打開cmd,輸入如下內(nèi)容:
c:\>sqlplus sys/admin@orcl as sysdba
如果輸出類似如下內(nèi)容,則表示連接成功:
SQL*Plus: Release 11.1.0.6.0 - Production on 星期二 7月 21 00:03:28 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
連接到:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
Copyright (c) 1982, 2007, Oracle. All rights reserved.
連接到:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
也可以這樣輸入:
c:\>sqlplus /nolog
SQL> conn sys@orcl as sysdba
輸入口令:admin
SQL> conn sys@orcl as sysdba
輸入口令:admin
4、注意問題:
a、以sys用戶登陸后要加"as sysdba",否則可能出現(xiàn)如下錯(cuò)誤:
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
b、如果不指定tnsnames.ora,則可能出現(xiàn)如下錯(cuò)誤:
ORA-12154: TNS: 無法解析指定的連接標(biāo)識符
c、如果不需要Instant Client了,想刪除它,可能會發(fā)現(xiàn)無法刪除F:\Oracle\InstantClient\oci.dll。這時(shí),只要停止msdtc服務(wù):"net stop msdtc" ,然后再刪除即可。