How to enable command line history scrolling on SQL*Plus on unix?

Using the utility rlwrap one can perform command line scrolling on SQL*Plus similar to that is available on windows version of SQL*Plus. The source code for it can be downloaded from the following site: http://utopia.knoware.nl/~hlub/uck/rlwrap/. To build rlwrap executable needs a library readline is needed which can be downloaded from http://directory.fsf.org/project/readline/.

One of the requirements to build this to have a C compiler like gcc.

To build the readline library after it’s downloaded and untar.
# directory where the source code was untarred, you will need to rename the directory to “readline” as the rlwrap looks for the header file readline.h in a readline folder
$ cd /u01/code/readline
# This step builds the makefile and it also checks if you have the necessary tools (gcc) and inspects your current env. It logs the information in config.log
$ ./configure
# step to build the library libreadline.a
$ make -f Makefile
# verify the library is built
$ ls -l libreadline.a
-rw-r–r– 1 user dba 1732206 Dec 12 17:28 libreadline.a

# step to build rlwrap
$ cd /u01/code/rlwrap-0.30
# set CPPFLAGS which is used to set for C parser, if not set it will not will be able to find the headerfile readline.h which is used to find the version
$ export CPPFLAGS=-I/u01/code/readline
# This step builds the makefile and it also checks if you have the necessary tools (gcc) and inspects your current env. It logs the information in config.log
$ ./configure CFLAGS=-I/u01/code LDFLAGS=-L/u01/code/readline
# this step will build the rlwrap executable, if no errors then it will build the rlwarp in the src directory
$ make

Then you can copy it this executable to /usr/local/bin and add this directory the PATH env so you can use it.

Example: $ rlwrap sqlplus
Enter user-name: username
Enter password: *******

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s