SQL*Plus Login Configuration (login.sql)
What This Script Does
Section titled “What This Script Does”Configures the SQLPlus environment with custom settings and creates a dynamic prompt that displays the current user and instance name. This script is typically placed in the SQLPlus search path to automatically execute when starting SQL*Plus sessions.
The Script
Section titled “The Script”rem login.sqlremttitle 'SQL*Plus Login Configuration'remset term offset pause offremcol the_sid noprint new_val the_sidcol the_user noprint new_val the_userremselect instance_name the_sid, user the_userfrom v$instance/remset sqlprompt "&the_user@&the_sid:SQL> "remundefine the_sidundefine the_userremset serveroutput onset term onset trimspool onset linesize 200set pagesize 100set timing onset time onset suffix sqlset verify offset num 18set editfile C:/logs
-- Automatic execution when placed in SQL*Plus path-- Or manual execution:@login.sql
Parameters
Section titled “Parameters”The script requires no input parameters and automatically detects the current instance and user.
Required Privileges
Section titled “Required Privileges”SELECT on V$INSTANCE-- (Usually available to all users)
Key Configuration Settings
Section titled “Key Configuration Settings”Prompt Customization
-- Creates prompt showing: username@instance:SQL>-- Example: SCOTT@PROD:SQL>set sqlprompt "&the_user@&the_sid:SQL> "
Display Settings
set linesize 200 -- Set line width to 200 charactersset pagesize 100 -- Set page length to 100 linesset timing on -- Show execution timingset time on -- Show current timeset serveroutput on -- Enable DBMS_OUTPUT display
Behavior Settings
set verify off -- Suppress substitution variable displayset trimspool on -- Remove trailing spaces in spool filesset suffix sql -- Default file extension for scriptsset num 18 -- Number column widthset pause off -- Disable pause between pages
File Settings
set editfile C:/logs -- Default edit file location
Customization Options
Section titled “Customization Options”Modify Prompt Format
-- Simple promptset sqlprompt "SQL> "
-- Instance onlyset sqlprompt "&the_sid:SQL> "
-- Include date/timeset sqlprompt "&the_user@&the_sid (&_DATE):SQL> "
Adjust Display Settings
-- For wide monitorsset linesize 300
-- For detailed outputset pagesize 200
-- For minimal outputset pagesize 20
Add Custom Settings
-- Additional useful settingsset echo off -- Don't echo commandsset feedback off -- Suppress row count feedbackset heading on -- Show column headingsset wrap on -- Wrap long lines
Environment Variables
Section titled “Environment Variables”The script uses SQL*Plus substitution variables:
&the_user
- Current database username&the_sid
- Current instance name
Common Use Cases
Section titled “Common Use Cases”Development Environment Setup
-- Place login.sql in SQL*Plus search path-- Automatic execution for consistent environment
DBA Administration
-- Clear identification of current connection-- Consistent formatting for all sessions
Team Standardization
-- Ensure all team members have same settings-- Reduce formatting inconsistencies
Production Safety
-- Clear instance identification in prompt-- Prevent accidental operations on wrong environment
Installation
Section titled “Installation”Windows
- Place in
%ORACLE_HOME%\sqlplus\admin\
directory - Or place in current working directory
- Or specify in SQLPATH environment variable
Unix/Linux
- Place in
$ORACLE_HOME/sqlplus/admin/
directory - Or place in home directory
- Or specify in SQLPATH environment variable
Benefits
Section titled “Benefits”Visual Confirmation
- Clear indication of current database connection
- Prevents accidental operations on wrong instance
- Easy identification in multiple SQL*Plus sessions
Consistent Environment
- Standardized display settings
- Predictable output formatting
- Improved readability
Productivity Enhancement
- Timing information for performance analysis
- Proper line width and page settings
- Server output enabled for debugging
Performance Impact
Section titled “Performance Impact”- Minimal Impact: Executes once per session
- Quick Execution: Simple queries and settings
- No Ongoing Overhead: Settings persist for session
Troubleshooting
Section titled “Troubleshooting”Prompt Not Updating
- Verify V$INSTANCE access permissions
- Check for syntax errors in script
- Ensure proper file placement
Settings Not Applied
- Confirm script is in SQL*Plus search path
- Check for conflicting glogin.sql settings
- Verify file permissions
Related Scripts
Section titled “Related Scripts”- name - Database name query
- Database-specific login scripts for different environments
- Team-specific customization scripts