Customizing Your SQL Prompt
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:
export SQLPATH=$HOME/scripts
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