使用sqlplus连接到Oracle DB

时间:2013-03-27 14:13:51

标签: 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 -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]

请帮助我在使用命令时遇到错误。

8 个答案:

答案 0 :(得分:10)

试试这个: sqlplus USER/PW@//hostname:1521/SID

答案 1 :(得分:4)

  

sqlplus用户名/密码@database

例如:

  

sqlplus hr / hr @ orcl

答案 2 :(得分:1)

简单方法(使用XE):

1)。配置你的tnsnames.ora

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = HOST.DOMAIN.COM)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

你可以用IP地址替换HOST.DOMAIN.COM,默认情况下TCP端口是1521(ckeck),看看这个配置的名称是XE

2)。使用名为sqlplus的应用程序:

sqlplus SYSTEM@XE

SYSTEM应该被授权的USER替换,并在出现提示时输入密码

3)。在防火墙上查看某些阻塞TCP端口的可能性,如果出现

则修复它

答案 3 :(得分:1)

从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)))"

请参阅链接上的说明:https://stackoverflow.com/a/45064809/6332029

谢谢!

答案 4 :(得分:0)

如果要连接oracle数据库

  1. 打开sql提示符
  2. 与sysdba连接 对于XE-conn / as sysdba 对于IE-conn sys as sysdba
  3. 然后按下面的命令启动数据库 启动;
  4. 一旦启动意味着您现在可以访问oracle数据库。 如果你想连接另一个用户,你可以写conn用户名/密码 例如康斯科特/老虎; 它将显示连接........

答案 5 :(得分:0)

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

答案 6 :(得分:0)

正如David Aldridge解释的那样,你的括号应该在sqlplus命令之后立即开始,所以它应该是:

sqlplus 'test/test@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname.com )(PORT=1521)))(CONNECT_DATA=(SID=mysid))'

答案 7 :(得分:0)

会是这样的

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;
!

这里

ORACLE_UID=<user name>
ORACLE_PWD=<password>
ORACLE_DB=//<host>:<port>/<DB name>