使用sqlplus连接到Oracle数据库
我正在Unix环境中使用以下命令连接到Oracle数据库:使用sqlplus连接到Oracle数据库,oracle,unix,sqlplus,Oracle,Unix,Sqlplus,我正在Unix环境中使用以下命令连接到Oracle数据库: sqlplus test/test@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))' 但我得到了以下错误: Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements. Usage 1: sqlplus
sqlplus test/test@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))'
但我得到了以下错误:
Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements.
Usage 1: sqlplus -H | -V
-H Displays the SQL*Plus version and the
usage help.
-V Displays the SQL*Plus version.
Usage 2: sqlplus [ [<option>] [{logon | /nolog}] [<start>] ]
<option> is: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S]
使用SQL*Plus执行SQL、PL/SQL和SQL*Plus语句。
用法1:sqlplus-H |-V
-H显示SQL*Plus版本和
使用帮助。
-V显示SQL*Plus版本。
用法2:sqlplus[[[{logon |/nolog}][]
is:[-C][-L][-M”“][-R][-S]
请帮助我在使用命令时犯了什么错误
sqlplus用户名/password@database
例如:
sqlplus人力资源/hr@orcl
如果要连接到oracle数据库
sqlplus用户/PW@//hostname:1521/SID
简易方法(使用XE):
1) 。配置您的tnsnames.ora
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = HOST.DOMAIN.COM)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
您可以将HOST.DOMAIN.COM替换为IP地址,默认情况下TCP端口为1521(请检查),并且该配置的名称为XE
2) 。使用名为sqlplus的应用程序:
sqlplus SYSTEM@XE
系统应替换为授权用户,并在出现提示时输入密码
3) 。如David Aldridge所解释的,您的括号应该在sqlplus命令之后开始,因此应该是:
tnsping xe --if you have installed express edition
tnsping orcl --or if you have installed enterprise or standard edition then try to run
--if you get a response with your description then you will write the below command
sqlplus --this will prompt for user
hr --user that you have created or use system
password --inputted at the time of user creation for hr, or put the password given at the time of setup for system user
hope this will connect if db run at your localhost.
--if db host in a remote host then you must use tns name for our example orcl or xe
try this to connect remote
hr/pass...@orcl or hr/pass...@xe --based on what edition you have installed
sqlplus'test/test@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com)(PORT=1521))(CONNECT_DATA=(SID=mysid))”
类似于此
sqlplus -s /nolog <<-!
connect ${ORACLE_UID}/${ORACLE_PWD}@${ORACLE_DB};
whenever sqlerror exit sql.sqlcode;
set pagesize 0;
set linesize 150;
spool <query_output.dat> APPEND
@$<input_query.dat>
spool off;
exit;
!
从Unix用户连接Oracle数据库的不同方法有:
[oracle@OLE1 ~]$ sqlplus scott/tiger
[oracle@OLE1 ~]$ sqlplus scott/tiger@orcl
[oracle@OLE1 ~]$ sqlplus scott/tiger@192.168.244.128:1521/orcl
[oracle@OLE1 ~]$ sqlplus scott/tiger@//192.168.244.128:1521/orcl
[oracle@OLE1 ~]$ sqlplus "scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ole1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
请参见链接中的说明:
谢谢!您的括号是否平衡?是的,这就是问题所在,我在命令中遗漏了一个结束括号。非常感谢David。如果您的客户端配置为允许EZCONNECT进行Oracle名称解析,您可以使用sqlplus测试/test@hostname.com:1521/改为mysid-IMHO更简单。请不要在答案中包含指向无关网站的链接它看起来像垃圾邮件。对于端口,你应该检查
oracle\product\11.2.0\dbhome\u 1\NETWORK\ADMIN\tnsnames.ora
,如果你以前安装过另一个oracle,有时它是1522。我有1526个基础,是的,它可能不同。对我来说很明显。
[oracle@OLE1 ~]$ sqlplus scott/tiger
[oracle@OLE1 ~]$ sqlplus scott/tiger@orcl
[oracle@OLE1 ~]$ sqlplus scott/tiger@192.168.244.128:1521/orcl
[oracle@OLE1 ~]$ sqlplus scott/tiger@//192.168.244.128:1521/orcl
[oracle@OLE1 ~]$ sqlplus "scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ole1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"