Oracle® Database 2 Day Developer's Guide 11g Release 2 (11.2) Part Number E10766-01 |
|
|
View PDF |
You can connect to Oracle Database only through a client program, such as SQL*Plus or SQL Developer.
This chapter contains the following sections:
SQL*Plus is a client program with which you can access Oracle Database. This section shows how to start SQL*Plus and connect to Oracle Database.
To connect to Oracle Database from SQL*Plus:
If you are on a Windows system, display a Windows command prompt.
At the command prompt, type sqlplus
and press the key Enter.
SQL*Plus starts and prompts you for your user name.
Type your user name and press the key Enter.
SQL*Plus prompts you for your password.
Type your password and press the key Enter.
Note:
For security, your password is not visible on your screen.The system connects you to an Oracle Database instance.
You are in the SQL*Plus environment. At the SQL>
prompt, you can enter and run SQL*Plus commands, SQL statements, PL/SQL statements, and operating system commands.
To exit SQL*Plus, type exit
and press the key Enter.
Note:
Exiting SQL*Plus ends the SQL*Plus session, but does not shut down the Oracle Database instance.Example 2-1 starts SQL*Plus, connects to Oracle Database, runs a SQL SELECT
statement, and exits SQL*Plus. User input is bold.
Example 2-1 Connecting to Oracle Database from SQL*Plus
> sqlplus SQL*Plus: Release 11.2.0.0.1 - Beta on Mon Jun 9 15:31:26 2008 Copyright (c) 1982, 2008, Oracle. All rights reserved. Enter user-name: your_user_name Enter password: your_password Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.0.0 - Development With the Partitioning, Data Mining and Real Application Testing options SQL> select count(*) from employees; COUNT(*) ---------- 107 SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.0.0 - Development With the Partitioning, Data Mining and Real Application Testing options >
See Also:
"About SQL*Plus" for a brief description of SQL*Plus
SQL*Plus User's Guide and Reference for more information about starting SQL*Plus and connecting to Oracle Database
SQL Developer is a client program with which you can access Oracle Database. This section assumes that SQL Developer is installed on your system, and shows how to start it and connect to Oracle Database. If SQL Developer is not installed on your system, see Oracle Database SQL Developer User's Guide for installation instructions.
Note:
For the following procedure:To connect to Oracle Database from SQL Developer:
Access the menu from which you can select SQL Developer:
On a Windows system: From the Start menu, select All Programs.
On a Linux system:
On Gnome: Click Application.
On KDE: Click K.
Select Oracle - ORACLE_HOME.
Select Application Development.
Select SQL Developer.
If this is the first time you have started SQL Developer on your system, you are prompted to enter the full path to java
.exe
(for example, C:\jdk1.5.0\bin\java.exe
). Either type the full path after the prompt or browse to it, and then press the key Enter.
The Oracle SQL Developer window opens.
In the navigation frame of the window, click Connections.
The Connections pane appears.
In the Connections pane, click the icon New Connection.
The New/Select Database Connection window opens.
In the New/Select Database Connection window, type the appropriate values in the fields Connection Name, Username, and Password.
For security, the password characters that you type appear as asterisks.
Near the Password field is the check box Save Password. By default, it is deselected. Oracle recommends accepting the default.
In the New/Select Database Connection window, click the tab Oracle.
The Oracle pane appears.
In the Oracle pane:
For Role, accept the default.
For Connection Type, accept the default (Basic).
In the fields Hostname and Port, type the appropriate values.
Select the option SID.
In the SID field, type the appropriate value.
In the New/Select Database Connection window, click the button Test.
The connection is tested. If the connection succeeds, the Status indicator changes from blank to Success
.
If the test succeeded, click the button Connect.
The New/Select Database Connection window closes. The Connections pane shows the connection whose name you entered in the Connection Name field in step 7.
You are in the SQL Developer environment.
To exit SQL Developer, select Exit from the File menu.
Note:
Exiting SQL Developer ends the SQL Developer session, but does not shut down the Oracle Database instance. The next time you start SQL Developer, the connection you created using the preceding procedure still exists. SQL Developer prompts you for the password that you supplied in step 7 (unless you selected the check box Save Password).See Also:
"Connecting to Oracle Database as User HR from SQL Developer"
"About SQL Developer" for a brief description of SQL Developer
Oracle Database SQL Developer User's Guide for more information about using SQL Developer to create connections to Oracle Database
This section shows how to unlock the HR
account and connect to Oracle Database as the user HR
, who owns the HR
sample schema that the examples and tutorials in this document use.
To do the tutorials and examples in this document, and create the sample application, you must connect to Oracle Database as the user HR
from SQL Developer. The HR
sample schema is the development environment for the sample application.
Topics:
By default, when the HR
schema is installed, the HR
account is locked and its password is expired. You can connect to Oracle Database as the user HR
only if the HR
account is unlocked.
Note:
For the following procedure, you need the name and password of a user who has theALTER
USER
system privilege (for example, SYSTEM
).To unlock the HR account and reset its password:
Using SQL*Plus, connect to Oracle Database as a user with the ALTER
USER
system privilege.
For instructions, see "Connecting to Oracle Database from SQL*Plus".
At the SQL>
prompt, unlock the HR
account and reset its password:
Caution:
Choose a secure password. For guidelines for securing passwords, see Oracle Database Security Guide.ALTER USER HR ACCOUNT UNLOCK IDENTIFIED BY password;
The system responds:
User altered
The HR
account is unlocked and its password is password
.
Now you can connect to Oracle Database as user HR
with the password password
. For instructions, see either "Connecting to Oracle Database from SQL*Plus" or "Connecting to Oracle Database from SQL Developer".
See Also:
Oracle Database 2 Day + Security Guide for information about predefined user accounts provided by Oracle Database, including HR
Oracle Database SQL Developer User's Guide for information about accessing SQL*Plus within SQL Developer
Oracle Database 2 Day DBA for information about using Enterprise Manager to unlock user accounts
This section shows how to connect to Oracle Database as the user HR
from SQL*Plus, if the HR
account is unlocked.
To connect to Oracle Database as user HR from SQL*Plus:
Note:
For this task, you need the password for theHR
account.If you are connected to Oracle Database, close your current connection.
Follow the directions in "Connecting to Oracle Database from SQL*Plus", entering the user name HR
at step 3 and the password for the HR
account at step 4.
You are now connected to Oracle Database as the user HR
.
See Also:
SQL*Plus User's Guide and Reference for an example of using SQL*Plus to create anHR
connectionThis section shows how to connect to Oracle Database as the user HR
from SQL Developer, if the HR
account is unlocked.
Note:
For the following procedure, you need the password for theHR
account.To connect to Oracle Database as user HR from SQL Developer:
Follow the directions in "Connecting to Oracle Database from SQL Developer", entering the following values at steps 7 and 9.
At step 7:
For Connection Name, enter hr_conn
.
(You can enter a different name, but the tutorials in this document assume that you named the connection hr_conn
.)
For Username, enter HR
.
For Password, enter the password for the HR
account.
At step 9:
For Role, accept the default.
For Connection Type, accept the default (Basic).
For Hostname, enter localhost
.
For Port, enter 1521
.
For SID, enter orcl
.
At step 11, the name of the connection, hr_conn
, appears in the Connections pane of the Oracle SQL Developer window.
You are now connected to Oracle Database as the user HR
.