【问题标题】:Connect to Oracle DB using sqlplus使用 sqlplus 连接到 Oracle 数据库
【发布时间】:2013-03-17 15:58:15
【问题描述】:

我在 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]

请帮助我在使用命令时出错的地方。

【问题讨论】:

  • 你的括号平衡了吗?
  • 是的,这就是问题所在,我错过了命令中的 1 个右括号。非常感谢大卫。
  • 如果您的客户端配置为允许 EZCONNECT 进行 Oracle 名称解析,您可以改用 sqlplus test/test@hostname.com:1521/mysid - 恕我直言更容易。

标签: oracle unix sqlplus


【解决方案1】:

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

【讨论】:

  • 端口请查看oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora,如果您之前安装过另一个Oracle,有时是1522。
  • 我有 1526 个碱基,是的,它可以不同。对我来说很明显。
【解决方案2】:

sqlplus 用户名/密码@数据库

例如:

sqlplus hr/hr@orcl

【讨论】:

    【解决方案3】:

    从 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】:

      简单的方法(使用 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(检查一下),看看这个配置的名字是XE

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

      sqlplus SYSTEM@XE
      

      SYSTEM应替换为授权用户,并在出现提示时输入密码

      3)。查看防火墙以了解某些 TCP 端口被阻止的可能性,如果出现则修复它

      【讨论】:

        【解决方案5】:

        如果你想连接oracle数据库

        1. 打开 sql 提示符
        2. 与 sysdba 连接 对于 XE-conn / 作为 sysdba 对于 IE-conn sys as sysdba
        3. 然后通过以下命令启动数据库 启动;

        一旦启动意味着您现在可以访问 oracle 数据库。 如果你想连接另一个用户,你可以写 conn 用户名/密码 例如康涅狄格/老虎; 它将显示已连接........

        【讨论】:

        • 请不要在您的答案中包含指向不相关网站的链接 - 这看起来像是垃圾邮件。
        【解决方案6】:
        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
        

        【讨论】:

          【解决方案7】:

          正如 David Aldridge 所解释的,您的括号应该在 sqlplus 命令之后开始,所以应该是:

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

          【讨论】:

            【解决方案8】:

            应该是这样的

            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>
            

            【讨论】:

              猜你喜欢
              • 2018-11-11
              • 1970-01-01
              • 2018-05-28
              • 1970-01-01
              • 2023-03-22
              • 1970-01-01
              • 2015-04-11
              • 2012-04-11
              • 2011-11-12
              相关资源
              最近更新 更多