Skip Headers
Oracle® Database Express Edition 2 Day DBA
10g Release 2 (10.2)

Part Number B25107-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

3 Connecting to the Database

In addition to using the Oracle Database XE graphical user interface to work with the database, you can use the set of command-line utilities that come with Oracle Database XE. Table 3-1 lists these utilities. To use these utilities, you must understand how to connect to the database with them.

Table 3-1 Oracle Database XE Command-Line Utilities

Utility Purpose See Also

SQL Command Line (SQL*Plus)

Administer the database; create, alter and drop database objects; run SQL queries; and run SQL and PL/SQL scripts.

"Using SQL Command Line" in Oracle Database Express Edition 2 Day Developer Guide

Data Pump

Export and import data from one Oracle database to another.

"Importing, Exporting, Loading, and Unloading Data"


Import and Export

Export and import data from one Oracle database to another.

"Importing, Exporting, Loading, and Unloading Data"


SQL*Loader

Bulk-load data into the database from external files.

"Importing, Exporting, Loading, and Unloading Data"



Although connection concepts apply to all utilities, this section focuses on SQL Command Line (SQL*Plus), because you use it for database administration. The following topics are covered:

See Also:

The following documents, for information on how to connect to the database from your application:

About Local and Remote Connections

­Oracle Database XE supports connections between SQL Command Line (SQL*Plus) and the database either locally, or remotely over a TCP/IP network. The method that you use to connect to Oracle Database XE with SQL Command Line depends on whether you are initiating a local connection or a remote connection. Local and remote connections are explained in the following sections:

See Also:

About Local Connections

Connecting locally means running SQL Command Line (or any other Oracle command-line utility) on the same host computer where Oracle Database XE is installed (the "Oracle Database XE host computer") and then initiating a database connection from SQL Command Line (or other utility). To connect locally, you must supply only a database user name and password. For example, Figure 3-1 shows a user connecting locally with SQL Command Line and entering a connect command that supplies the user name hr and password hr.

Figure 3-1 Local Connection

Description of Figure 3-1 follows
Description of "Figure 3-1 Local Connection"

Environment Variables

Before making a local connection on Linux, you must set environment variables. See "Setting Environment Variables" for more information.

Note:

Logging in to the Oracle Database XE host computer with an ssh (or telnet) session and then starting SQL Command Line (or other Oracle command-line utility) is considered a local connection, even though you start the ssh (or telnet) application on a remote computer.

About Remote Connections

Connecting remotely means running SQL Command Line (or any other Oracle command-line utility) on a computer other than the Oracle Database XE host computer, and then initiating a database connection from SQL Command Line (or other utility) over the network.

Oracle Client Software

The remote computer must have Oracle client software installed. It is through Oracle client software that Oracle command-line utilities (and your applications) connect to the database. Oracle Database XE accepts connections from all of the following types of Oracle client software:

  • Oracle Database Express Edition Client (Oracle Database XE Client)

    When you install Oracle Database XE, Oracle Database XE Client is also installed on the same computer. You can install Oracle Database XE Client separately on remote computers. It is available at

    http://www.oracle.com/technology/xe

  • Instant Client

    Instant Client is available at

http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html

  • Oracle client software for Oracle Database Enterprise Edition or Standard Edition (all supported releases of Oracle Database 8, 8i, 9i, and 10g)

All Oracle client software includes Oracle Net, which is the Oracle network software that enables client applications on one computer to connect to databases on another computer over a network.

Connect Strings

To connect remotely, you must supply not just a user name and password, but a complete Oracle Net connect string. In addition to the database user name and password, a connect string includes a host name or host IP address, an optional TCP port number, and an optional database service name. These additional parameters are required to help Oracle Net find the right host computer and connect to Oracle Database XE. An Oracle Net connect string has the following format:

username/password@[//]host[:port][/service_name]

where:

  • // is optional

  • host is the host name or IP address of the computer that is running Oracle Database XE

  • port (optional) is the TCP port number on which the Oracle Net listener is listening. If not specified, the default port number 1521 is assumed.

  • service_name (optional) is the name of the database service to which to connect. For Oracle Database XE, the service name is XE. If service_name is omitted, Oracle Database XE Client appends a request for the default database service, which is configured during installation as XE.

Note:

Only Oracle Database XE Client supports the notion of a default database service. If you connect remotely from any Oracle client software other than Oracle Database XE Client, you must include the XE service name.

For example, Figure 3-2 shows a user connecting remotely with SQL Command Line and entering a connect command that includes a connect string that supplies: the user name hr, the password hr, and the host name dbhost.xyz.com. This connect string connects to the default database service (XE) on the default port (1521).

Figure 3-2 Remote Connection

Description of Figure 3-2 follows
Description of "Figure 3-2 Remote Connection"

Environment Variables

Before making a remote connection from Linux, you must set environment variables. See "Setting Environment Variables" for more information.

Remote Connection Examples

In the following examples of SQL Command Line connect commands, Oracle Database XE is running on the host computer mydbserver.mydomain.com.

Example 1 This example initiates a remote connection from Oracle Database XE Client, using the default port number.

CONNECT system/mypassword@mydbserver.mydomain.com

Example 2 This example initiates a remote connection from Oracle Database XE Client, using a nondefault port number (1522):

CONNECT system/mypassword@mydbserver.mydomain.com:1522

Example 3 This example initiates a remote connection using the default port number, and includes the optional service name.

CONNECT system/mypassword@mydbserver.mydomain.com/XE

Setting Environment Variables

SQL Command Line (SQL*Plus) and other Oracle utilities retrieve configuration information from operating system environment variables. This section explains how to set these environment variables, and contains the following topics:

Setting Environment Variables on the Windows Platform

On the Windows platform, environment variables are stored in the Windows registry, and are automatically set for you. You need not take any action involving environment variables before initiating a database connection.

Setting Environment Variables on the Linux Platform

On the Linux platform, before running SQL Command Line or other Oracle utilities from a terminal session, you must set some environment variables for that session. The procedure for setting environment variables depends on whether you are connecting locally, or connecting remotely from Oracle Database XE Client.

Setting Environment Variables for a Local Connection

To set environment variables when connecting locally, enter one of the following commands in a terminal session.

For Bourne, Korn, or Bash shell:

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh

For C shell:

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.csh

See "Environment Variables Reference for Linux" for more information.

Note:

There is no need to set environment variables before running SQL Command Line from the K menu (KDE) or Applications menu (Gnome).

Setting Environment Variables for a Remote Connection

To set environment variables when connecting remotely from Oracle Database XE Client, enter one of the following commands in a terminal session at the remote computer:

For Bourne, Korn, or Bash shell:

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin/oracle_env.sh

For C shell:

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin/oracle_env.csh

See "Environment Variables Reference for Linux" for more information.

Connecting Locally with SQL Command Line

Connecting locally means running SQL Command Line (SQL*Plus) and Oracle Database XE on the same computer. There are two ways to start a local connection with SQL Command Line:

Starting SQL Command Line from the Desktop

To start SQL Command Line from the desktop and connect locally:

  1. Do one of the following:

    • On Windows: Click Start, point to Programs (or All Programs), point to Oracle Database 10g Express Edition, and then select Run SQL Command Line.

    • On Linux with Gnome: In the Applications menu, point to Oracle Database 10g Express Edition, and then select Run SQL Command Line.

    • On Linux with KDE: Click the icon for the K Menu, point to Oracle Database 10g Express Edition, and then select Run SQL Command Line.

    A SQL Command Line command window opens.

  2. At the SQL Command Line prompt, enter the following command:

    CONNECT username/password
    
    

    For example, to connect as user HR with the password PEOPLE, enter the following command:

    CONNECT HR/PEOPLE
    

Starting SQL Command Line from a Terminal Session or Command Window

To start SQL Command Line from a terminal session or command window and connect locally:

  1. If not already open, open a terminal session (Linux) or a command window (Windows).

  2. (Linux only) If the required environment variables are not already set for your session, set them as described in "Setting Environment Variables on the Linux Platform".

  3. Enter the following command at the operating system prompt:

    SQLPLUS /NOLOG
    
    
  4. At the SQL Command Line prompt, enter the following command:

    CONNECT username/password
    
    

    For example, to connect as user HR with the password PEOPLE, enter the following command:

    CONNECT HR/PEOPLE
    

Connecting Remotely with SQL Command Line

Connecting remotely means running SQL Command Line (SQL*Plus) on one computer (the remote computer), and then initiating a connection to Oracle Database XE on a different computer.

To initiate a remote connection from SQL Command Line using the Oracle Database XE Client:

  1. On the remote computer, start a terminal session (Linux) or open a command window (Windows.)

    If prompted for host credentials, log in to the remote computer.

  2. (Linux only) If the required environment variables are not already set for your session, set them as described in "Setting Environment Variables on the Linux Platform".

  3. Enter the following command at the operating system prompt:

    SQLPLUS /NOLOG
    
    
  4. Enter a CONNECT command at the SQL Command Line prompt, supplying a connect string.

    CONNECT username/password@[//]host[:port][/service_name]
    
    

    See "About Remote Connections" for a description and examples of connect strings.

Environment Variables Reference for Linux

This section provides reference information for setting environment variables on Linux for the following two scenarios:

Table 3-2 lists the environment variables that you must set for each of these scenarios. Table 3-3 provides environment variable descriptions and required values.

Table 3-2 Required Linux Environment Variables for Connecting with Oracle Utilities

Connection Type Required Environment Variables

Local


ORACLE_SID
ORACLE_HOME
PATH
NLS_LANG
LD_LIBRARY_PATH

Remote, using Oracle Database XE Client


ORACLE_HOME
PATH
NLS_LANG
LD_LIBRARY_PATH
SQLPATH

Table 3-3 Environment Variable Descriptions and Values for Linux

Variable Name Description Required Value

ORACLE_SID

Oracle Instance ID

XE

ORACLE_HOME

Oracle home directory

For local connection:

/usr/lib/oracle/xe/app/oracle/product/10.2.0/server

For remote connection with Oracle Database XE Client:

/usr/lib/oracle/xe/app/oracle/product/10.2.0/client

PATH

Search path for executables. (Must add $ORACLE_HOME/bin to the path.)

For Bourne, Korn, or Bash shell: $ORACLE_HOME/bin:$PATH

For C shell: $ORACLE_HOME/bin:${PATH}

NLS_LANG

Locale (language and territory used by client applications and the database; character set used by client applications)

(The desired language, territory, and character set. See Oracle Database Express Edition Installation Guide for Linux for details.)

Defaults to AMERICAN_AMERICA.US7ASCII

LD_LIBRARY_PATH

Search path for shared libraries. (Must add $ORACLE_HOME/lib to the path.

$ORACLE_HOME/lib:$LD_LIBRARY_PATH

SQLPATH

Search path used by SQL Command Line (SQL*Plus) for *.sql scripts. Contains a colon-separated list of paths. Must include the location of the site profile script, glogin.sql.

$ORACLE_HOME/sqlplus/admin


Example

The following are the Bash shell commands that set the required environment variables for a local connection on a Linux installation in the United States:

ORACLE_SID=XE;export ORACLE_SID
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server;export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH;export PATH
NLS_LANG=AMERICAN_AMERICA.AL32UTF8;export NLS_LANG
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH;export LD_LIBRARY_PATH

Environment Variable Scripts

Oracle Database XE and Oracle Database XE Client ship with two shell scripts that you can use to easily set environment variables. The scripts are located in $ORACLE_HOME/bin and are named as follows:


oracle_env.sh (for Bourne, Korn, or Bash shell)
oracle_env.csh (for C shell)

You can invoke these scripts from within dot files so that environment variables are set automatically each time that you start a new terminal session (start a new shell). The following is an example of a command that you can add to the .cshrc file in your home directory:

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.csh