Despite living in the era of GUI tools such as PL/SQL Developer, there are times when a simple text browser is all you want. Sometimes you may not have access to an IDE, or you just want to mail a simple example to a colleague or web forum, or you may not trust your fancy IDE to give you the actual results without manipulating them in some way, and sometimes you may prefer the text-based Explain Plan results you get from DBMS_XPLAN. Whatever the reason, it is worth knowing your way around SQL*Plus.1
Two versions of SQL*Plus are provided on the Windows platform. The deprecated GUI version can seem initially more attractive as it has a cheerful white screen, an icon, more buttons, and "File > Spool" and "Options > Environment" options, but it is actually less useful. The directional keys simply scroll up or across the screen, rather than retrieving previous commands or navigating in the current record. You can't change the font or the colours. There is no option to paste copied text with a right-mouseclick. I will therefore pretend that it does not exist, and look at the character mode version.
Much as I love Unix (and my Mac), it has to be said that the Windows version of SQL*Plus is better than the Unix one because it is more configurable and comes with command-line history.
One strength of the character mode sqlplus.exe is that it simply runs in the Windows command window (cmd.exe). If you have never used sqlplus.exe before but you have configured your cmd window the way you like it, you will find that sqlplus.exe inherits these settings. It also uses a fraction of the system resources (sqlplusw.exe hogs around 12MB as soon as you start it up, while sqlplus.exe is initially listed in Task Manager as Zero KB, only rising to a few kilobytes as you fill the scroll buffer). The following steps essentially describe how to customise cmd windows.
First, set up a folder for files. By default in Windows, the working folder is the one that contains the executable, in this case the "bin" directory of the Oracle client installation. This is not a good place for your SQL*Plus scripts. Using Windows Explorer, create a folder called something like "SQL" in a convenient location. On some company sites, I have used the private space on the network drive provided, although on others with less reliable networks I have set it up on the C: drive, directly under Oracle. It's up to you, but the important thing is to have a dedicated folder for SQL*Plus stuff.
Find the sqlplus.exe executable (not sqlplusw.exe!) in the Oracle bin folder. This is usually something like c:\Oracle\bin, although the default varies by Oracle release, and of course you might have installed the Oracle client yourself (actually quite a good idea if you are allowed to, as the version on corporate desktops is often way out of date - often DBAs upgrade the database but it isn't their job to upgrade the desktop client). Using the right mouse button, drag it to the desktop and select "Create shortcuts here". Change the name of the new shortcut to [the username you will use]@[the instance name you will connect to], for example "william@dev". You may want to leave a space before the "@" to allow the label to wrap. You will now have a blank-looking icon with a helpful label under it.
Right-click the shortcut and choose Properties.
Now work through the other property tabs (you will notice that there are more options available than sqlplusw.exe gave you).
Experiment with text and background colours, so that they have reasonable contrast (not grey on grey) and don't glare (pink on orange), and so that the cursor is visible (again, avoid a mid-grey background as it produces a mid-grey cursor). I often like to use a neutral blue or green for development and test environments, and red for production. Anything but white on black. You can pick preset colours from the list and then adjust their RGB field values as you prefer. Higher numbers are paler.
Hit the "F1" key for additional online help for each option.
You can probably go smaller than the default size and get more on the screen without losing legibility. I like Lucida Console.
The default is 80 characters wide by 24 high. Again, you can make it bigger without taking up too much of your desktop.
Now double-click that shortcut to fire up SQL*Plus, and log in.
By default this will invoke Notepad.exe and edit a new file named "login.sql". Notice that we are now working in the "SQL" folder we created earlier.
© William Robertson 2005, 2011 www.williamrobertson.net