Vous êtes sur la page 1sur 2

Customizing Your SQL Prompt

DBAs often use SQL*Plus to perform daily administrative tasks. Often, you'll work on servers that
contain multiple databases. Obviously, each database contains multiple user accounts. When connected
to a database, you can run the following commands to verify your username and database connection:
SQL> show user;
SQL> select name from v$database;
A more efficient way to determine your username and SID is to set your SQL prompt to display
that information. For example:
SQL> SET SQLPROMPT '&_USER.@&_CONNECT_IDENTIFIER.> '
An even more efficient way to configure your SQL prompt is to have it automatically run the SET
SQLPROMPT command when you log in to SQL*Plus. Follow these steps to fully automate this:

1. Create a file named login.sql, and place in it the SET


SQLPROMPT command.
2. Set your SQLPATH operating system variable to include the directory
location of login.sql. In this example, the SQLPATHoperating system
variable is set in the .bashrc operating system file, which is executed each
time a new shell is logged in to or started. Here is the entry:

export SQLPATH=$HOME/scripts

3. Create a file named login.sql in the HOME/scripts directory. Place the


following line in the file:

SET SQLPROMPT '&_USER.@&_CONNECT_IDENTIFIER.> '

4. To see the result, you can either log out and log back in to your server, or
source the .bashrc file directly:

$ . ./.bashrc

Now, log in to SQL. Here is an example of what the SQL*Plus prompt looks like:
SYS@devdb1>
If you connect to a different user, this should be reflected in the prompt:
SQL> conn system/foo
The SQL*Plus prompt now displays
SYSTEM@devdb1
Setting your SQL prompt is an easy way to remind yourself which environment and user you're
currently connected as. This will help prevent you from accidentally running a SQL statement in the
wrong environment. The last thing you want is to think you're in a development environment, and then
discover that you've run a script to delete objects while connected in a production environment.
Table 3–2 contains a complete list of SQL*Plus variables that you can use to customize your
prompt.
Table 3–2. Predefined SQL*Plus Variables

Variable Description

_CONNECT_IDENTIFIER Connection identifier, such as the Oracle SID

_DATE Current date

_EDITOR Editor used by the SQL EDIT command

_O_VERSION Oracle version

_O_RELEASE Oracle release

_PRIVILEGE Privilege level of the current connected session

_SQLPLUS_RELEASE SQL*Plus release number

_USER Current connected user

Vous aimerez peut-être aussi