使用 sqlplus 连接到 Oracle DB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15661076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connect to Oracle DB using sqlplus
提问by Chaitanya
I am using below command in Unix environment to connect to Oracle database:
我在 Unix 环境中使用以下命令连接到 Oracle 数据库:
sqlplus test/test@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))'
But I am getting below error:
但我收到以下错误:
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]
Please help me where I am doing mistake in using the command.
请帮助我在使用命令时出错的地方。
回答by Alexander
try this:
sqlplus USER/PW@//hostname:1521/SID
尝试这个:
sqlplus USER/PW@//hostname:1521/SID
回答by Santhosh
sqlplus username/password@database
sqlplus 用户名/密码@数据库
Eg:
例如:
sqlplus hr/hr@orcl
sqlplus hr/hr@orcl
回答by Rajesh Chaudhary
Different ways to connect Oracle Database from Unix user are:
从 Unix 用户连接 Oracle 数据库的不同方法是:
[oracle@OLE1 ~]$ sqlplus scott/tiger
[oracle@OLE1 ~]$ sqlplus scott/tiger@orcl
[oracle@OLE1 ~]$ sqlplus scott/[email protected]: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)))"
Please see the explanation at link: https://stackoverflow.com/a/45064809/6332029
请参阅链接中的说明:https: //stackoverflow.com/a/45064809/6332029
Thanks!
谢谢!
回答by Daniel Antonio Nu?ez Carhuayo
Easy way (using XE):
简单的方法(使用 XE):
1). Configure your tnsnames.ora
1)。配置你的 tnsnames.ora
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = HOST.DOMAIN.COM)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
You can replace HOST.DOMAIN.COM with IP address, the TCP port by default is 1521 (ckeck it) and look that name of this configuration is XE
你可以用IP地址替换HOST.DOMAIN.COM,默认TCP端口是1521(检查它),看看这个配置的名称是XE
2). Using your app named sqlplus:
2)。使用名为 sqlplus 的应用程序:
sqlplus SYSTEM@XE
SYSTEM should be replaced with an authorized USER, and put your password when prompt appear
SYSTEM 应替换为授权用户,并在出现提示时输入密码
3). See at firewall for any possibilities of some blocked TCP ports and fix it if appear
3)。查看防火墙以了解某些被阻止的 TCP 端口的任何可能性,并在出现时修复它
回答by Ahsan Habib
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
回答by Dopefish
As David Aldridge explained, your parentheses should start right after the sqlplus command, so it should be:
正如 David Aldridge 解释的那样,您的括号应该在 sqlplus 命令之后开始,所以它应该是:
sqlplus 'test/test@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))'
sqlplus 'test/test@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))'
回答by Manish Verma
it would be something like this
它会是这样的
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;
!
here
这里
ORACLE_UID=<user name>
ORACLE_PWD=<password>
ORACLE_DB=//<host>:<port>/<DB name>
回答by sudarshan
if you want to connect with oracle database
如果你想连接oracle数据库
- open sql prompt
- connect with sysdba for XE- conn / as sysdba for IE- conn sys as sysdba
- then start up database by below command startup;
- 打开sql提示
- 连接 sysdba for XE-conn / as sysdba for IE-conn sys as sysdba
- 然后通过以下命令启动启动数据库;
once it get start means you can access oracle database now. if you want connect another user you can write conn username/password e.g. conn scott/tiger; it will show connected........
一旦启动意味着您现在可以访问 oracle 数据库。如果你想连接另一个用户,你可以写 conn 用户名/密码,例如 conn scott/tiger;它会显示已连接......