Search code examples
sqlplusoracleclient

Oracle SqlPlus Command Line: is there a way to concatenate set options?


I need to set up some SET options in Oracle SQLplus command line program each time I use it, such as SET HEADING OFF and the likes to beautify my results. I found that I always have to input each line separately so Set different options and this is becoming annoying since I need to access it many times a day.

I found that there's no way to separate different SET commands with semicolons because it doesn't accept it:

SET HEADING OFF; SET LINESIZE 100;

returns an error

A solution could be adding them to a control script and create a shell alias, but I know control scripts execute and then exit and don't return you control over the command line.

So, anybody knows another solution? Or am I missing something?


Solution

  • Put all your commands in a ".sql" file (for example "format.sql") then execute them with the "@" command in Sql*plus (for example "@format").

    Note that it defaults to the ".sql" suffix when looking for the command file.

    For example, if "format.sql" contains the commands "set linesize 100" and "set pagesize 0":

    % sqlplus
    
    SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 18 08:39:03 2010
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    SQL> show linesize
    linesize 80
    SQL> @format
    SQL> show linesize
    linesize 100
    SQL> select 1+1 from dual;
         2