Skip to main content

CUSTOMIZING YOUR SQL PROMPT

I recently read an article that have an SQL prompt displyaing "user@hostname". As DBAs we frequently 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 information such as your username, database connection, and hostname: 

 SQL> show user; 

SQL> select name from v$databae; 

 A more efficient way to determine your username and SID is to set you 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 OS variable to include the directory location of login.sql. In this example the SQLPATH OS variable is set in the .bashrc OS 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 the SQL*Plus prompt: If you connect to a different user, this should be reflected in the prompt



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 an 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.

Comments

Popular posts from this blog

Oracle Database 19c Step by Step Installation On Oracle Linux 7.6

This post describes the installation of Oracle Database 19c 64-bit on Oracle Linux 7.6  x86-64 bit. The Linux server needs a minimum of 3G swap and secure Linux set to permissive. An example of this type of Linux installation can be seen here . Download Software Download the Oracle software from oracle edelivery . Oracle Installation Prerequisites Automatic Setup Use the "oracle-database-preinstall-19c" package to perform all your prerequisite setup. # yum install -y oracle-database-preinstall-19c If you are using RHEL7 or CentOS7, you can pick up the PRM from the OL7 repository and install it. It will pull the dependencies from your normal repositories. # yum install -y https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm Hosts File Set a fully qualified name for the server in the "/etc/hosts" file. < IP-address > < fully-qualified-machine-name > < machin...

Step by Step Installation of Oracle Database 12c on Solaris 10

In this article we will look at Installing Oracle 12C database on Solaris x86 64bit version. This article assumes that you already had Solaris 10 installed on Virtualbox. Preparing System for Installation The first step toward Oracle installation is to perform the pre-installation tasks. Configuring hosts file The first step is to properly name your host machine. The hostname should properly be provided with IP address for installation to continue. Ideally, your /etc/hosts file should look something like this. 192.168.34.47   sol10.cm 127.0.0.1 localhost Kernel Parameters The default installation of Solaris 10 is normally good enough for oracle database installation. You just have to configure one parameter. Use the command below to set the required kernel parameters. Remember that you will have to use the root login to run the commands. # projadd  -K "project.max-shm-memory=(privileged,4G,deny)" user.oracle To confirm that parameter has be...

How to Delete Old Trace & Dump files with ADRCI

The ADRCI command interpreter has multiple features:- Create a package with incident or problem information for Oracle Support Analyze diagnostic data within the Automatic Diagnostic Repository (ADR) Run health checks In this post, we'll be concentrating on deleting the old diagnostic files with ADRCI. Set your environment and run the ADRCI utility: $ adrci Use the following command to list the ADR homes: adrci> show home ADR Homes: diag/rdbms/db11g/DB11G diag/tnslsnr/sol10/listener Choose the ADR home from the list above: adrci> set home diag/rdbms/db11g/DB11G Check the current retention policy: adrci> show control Check the following columns in the output: LONGP_POLICY:- It is set to 365 days by default. It is responsible for Incidents and Health Monitor warnings. SHORTP_POLICY:- It is set to 30 days by default. It manages the trace and core dump files. Use the following commands to change the retention policy: Specify the time in hours: 10 Days = 240 ...