SQL*Plus and commandline history again

Various people have written about how you can add commandline history to sqlplus on Linux (and probably unix too?)

If someone is using Redhat Enterprise Linux, or one of the clones (Oracle Enterprise Linux, Centos), and are using yum (and I can see only very limited reasons for not using it; if you have to administer multiple machines, setting up a yum server will be a real timesaver, if the number is very small, use the internet repositories directly), add the EPEL repository: EPEL.

EPEL contains packages not present in the package collection of RHEL. One of these packages is rlwrap, which can give SQL*Plus commandline history. Installing rlwrap with EPEL is as simple as:

yum install rlwrap

Please notice this gives the SQL*Plus commandline some of the properties you have in the bash shell (when sqlplus is invoked with rlwrap of course: rlwrap sqlplus username/password@database). This means you can also search the history with the key combination CTRL + R.

Another property of the bash shell is autocompletion with the TAB key (something I use extensively). It would be extremely handy to have TAB autocompletion for Oracle keywords and a list of choices (if it can’t autocomplete because several options exist) with TAB - TAB (TAB two times).

Johannes Gritsch has written a little script to overcome some rlwrap difficulties and lists with autocompletion for keywords and data dictionary: http://www.linuxification.at/rlwrap_ext.html.en

Please note the tar needs to be extracted in ‘/usr/share/rlwrap’ when using the rlwrap version of EPEL, instead of the path listed in the readme. This path also needs to be modified in the ’sql+’ script.

Leave a Reply