Setting Up Login.SQL

Posted 11 April, 2006 - 12:07

To avoid repeatedly setting the same preferences each time SQL*Plus is started up, the following login.sql script collects these preferences for automatic execution:

Figure 1.0

REM
REM File:    Login.sql
REM Purpose: SQL*Plus login script.
REM


REM
REM Set the session's prompt to be something like:
REM username@global_name>
REM
SET TERMOUT OFF

COLUMN gname NEW_VALUE gname
SELECT
  LOWER(USER)
  || '@'
  || LOWER(global_name) AS gname
FROM global_name;
SET SQLPROMPT '&gname> '



REM
REM Other settings.
REM
SET TERMOUT ON
SET PAGESIZE 30
SET LINESIZE 132
SET LONG 132
SET TRIMSPOOL ON
REM SET SQLPROMPT '&_USER.@&_CONNECT_IDENTIFIER.> '
SET FEEDBACK ON
SET PAUSE ON PAUSE More...
SET SERVEROUTPUT ON SIZE 32000
SET EDITFILE "afiedt.buf"
DEFINE _editor=vi

REM
REM Set the date/time format to something a little more useful than the default.
REM
ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS';

REM
REM Various column formatting settings.
REM
COLUMN object_name   FORMAT A30
COLUMN object_type   FORMAT A30
COLUMN plan_plus_exp FORMAT A80

CLEAR SQL

REM
REM Ends.
REM

There is also a script named glogin.sql, normally found under $ORACLE_HOME/sqlplus/admin, which acts as a general login script that is executed before login.sql. This could be considered for customisation also.

Note that under ORACLE 10g, login.sql is executed upon each successful CONNECT attempt. This allows the SQL prompt to correctly reflect the username. It can also be a curse, so be aware that this happens.