如何使用 SQL Developer 或 Apex 连接 Oracle

How to connect Oracle using SQL Developer or Apex

我通过查看此 reference links 在 Ubuntu 14.04 上安装了 Oracle 11g。安装时,我没有看到任何创建用户名和密码的步骤

之后,我配置如下

$# sudo /etc/init.d/oracle-xe configure
Oracle Database 11g Express Edition Configuration

This will configure on-boot properties of Oracle Database 11g Express Edition.  The following questions will determine whether the database should be starting upon system boot, the ports it will use, and the passwords that will be used for database accounts.  Press <Enter> to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:8080

Specify a port that will be used for the database listener [1521]:1522

Specify a password to be used for database accounts.  Note that the same password will be used for SYS and SYSTEM.  Oracle recommends the use of different passwords for each database account.  This can be done after initial configuration:
Confirm the password:

Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:y

Starting Oracle Net Listener...Done
Configuring database...Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.
  1. 我尝试使用 http://localhost:8080/apex/f?p=4950 登录到 apex ==> 无法连接。 Firefox 无法与位于 localhost:8080.

  2. 的服务器建立连接
  3. 我尝试使用 SQL 开发人员

  4. 进行连接

Error: Status : Failure -Test failed: Listener refused the connection with the following error:ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

更多信息:

$ lsnrctl 状态

rgm@Motown:~$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 25-JUL-2015 08:49:19

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE))) STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date                23-JUL-2015 17:21:04
Uptime                    1 days 15 hr. 28 min. 14 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           XE
Listener Parameter File   /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/Motown/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Motown)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

listener.ora 文件

# listener.ora Network Configuration File:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      (ADDRESS = (PROTOCOL = TCP)(HOST = Motown)(PORT = 1521))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

使用 SYSTEM 登录 SqlPlus

rgm@Motown:~$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sat Jul 25 09:00:29 2015

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

ERROR:
ORA-01031: insufficient privileges


Enter user-name: SYSTEM
Enter password:
ERROR:
ORA-01033: ORACLE initialization or shutdown in progress
Process ID: 0
Session ID: 0 Serial number: 0


Enter user-name: oracle
Enter password:
ERROR:
ORA-01033: ORACLE initialization or shutdown in progress
Process ID: 0
Session ID: 0 Serial number: 0


SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

使用 oracle 登录 SqlPlus(su 到 oracle 用户)

rgm@Motown:~$ su oracle
Password:
oracle@Motown:/home/rgm$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Sat Jul 25 09:02:19 2015

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL>
SQL>

请帮助我解决使用 Apex 和 SQL 开发人员登录 SQL 的问题。

谢谢

您的 SQL 开发人员屏幕截图,您没有使用 tnsnames.ora - 没关系。

如何使用服务名称 = XE,而不是 SID。和本地主机到摩城。

在执行此操作之前 - 转到命令并查看是否可以 tnsping Motown。

c:\ tnsping 汽车城

您应该会在最后一行的某处看到 OK。我假设您已经安装了 Oracle 客户端工具

在您的安装日志中,它显示的端口是 1522 而不是默认的 1521。

Specify a port that will be used for the database listener [1521]:1522

在您的 SQL 开发人员屏幕截图中,您显示了一个使用默认值 1521 的连接对话框。如果不解决问题,至少正确设置端口号会让您更接近。