In the SQL*Plus itself is not possible to browsing history commands (except the last command executed, he can re-create using the “r” + Enter). On Windows, this can be quite well made via a function key F7, as shown in the picture. Elegantly can scroll through the history commands performed.

[Česká verze článku – SQL*Plus a historie příkazů v Linuxu pomocí rlwrap]

SQL*Plus history in Windows command line
SQL*Plus history in Windows command line

The Linux operating system can implement this by adding a wrapper for SQL*Plus as a program rlwrap (the program creates an intermediary between Bash and the environment of SQL*Plus).

UPDATE 20.08.2010 – If you are using Ubuntu, you can simply install rlwrap via “sudo aptitude install rlwrap

Installation procedure is as follows:

1. First download the rlwrap program from the server freshmeat – actual version. Perhaps using wget (URL of the current version of the program may change over time. Version of that show this installation is 0.37 and the name of the downloaded file is “rlwrap-0.37.tar.gz”):

oracle@ubuntu-server$ wget http://freshmeat.net/urls/de7d8482e030110354012880805e76fd

2. Unpack the downloaded file

oracle@ubuntu-server:~$ tar zxvf rlwrap-0.37.tar.gz
rlwrap-0.37/
rlwrap-0.37/completions/
rlwrap-0.37/completions/testclient
rlwrap-0.37/completions/coqtop
rlwrap-0.37/doc/
rlwrap-0.37/doc/rlwrap.man.in
rlwrap-0.37/doc/Makefile.am
rlwrap-0.37/doc/Makefile.in
...

3. Go to the directory with the program

oracle@ubuntu-server:~$ cd rlwrap-0.37/

4. Compile and run (when compiling I used the option “-prefix= usr”. By default, the program installs in /usr/local/bin, in this case I prefer /usr/bin, so I used the option “- prefix=…”)

oracle@ubuntu-server:~/rlwrap-0.37$ ./configure --prefix=/usr && make
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
...

If the configuration script fails:

configure: error:

You need the GNU readline library(ftp://ftp.gnu.org/gnu/readline/ ) to build
this program!

You must either (a) – download the readline library from the address ftp://ftp.gnu.org/gnu/readline/, unpack and compile it manually or (b) – as in my case, if you use Ubuntu (or similar Linux distribution), just install this library by using aptitude:

oracle@ubuntu-server:~/rlwrap-0.37$ sudo aptitude install libreadline6-dev

… and then start compiling rlwrap:

oracle@ubuntu-server:~/rlwrap-0.37$ ./configure --prefix=/usr && make

5. If the compilation completes without errors, you just install the program.

oracle@ubuntu-server:~/rlwrap-0.37$ sudo make install
Making install in doc
make[1]: Entering directory `/home/oracle/rlwrap-0.37/doc'
make[2]: Entering directory `/home/oracle/rlwrap-0.37/doc'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/share/man/man1" || /bin/mkdir -p "/usr/share/man/man1"
 /usr/bin/install -c -m 644 rlwrap.1 '/usr/share/man/man1'
make[2]: Leaving directory `/home/oracle/rlwrap-0.37/doc'
make[1]: Leaving directory `/home/oracle/rlwrap-0.37/doc'
Making install in src
make[1]: Entering directory `/home/oracle/rlwrap-0.37/src'
make[2]: Entering directory `/home/oracle/rlwrap-0.37/src'
test -z "/usr/bin" || /bin/mkdir -p "/usr/bin"
  /usr/bin/install -c rlwrap '/usr/bin'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oracle/rlwrap-0.37/src'
make[1]: Leaving directory `/home/oracle/rlwrap-0.37/src'
Making install in filters
make[1]: Entering directory `/home/oracle/rlwrap-0.37/filters'
make[2]: Entering directory `/home/oracle/rlwrap-0.37/filters'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/share/man/man3" || /bin/mkdir -p "/usr/share/man/man3"
 /usr/bin/install -c -m 644 RlwrapFilter.3pm '/usr/share/man/man3'
make[2]: Leaving directory `/home/oracle/rlwrap-0.37/filters'
make[1]: Leaving directory `/home/oracle/rlwrap-0.37/filters'
make[1]: Entering directory `/home/oracle/rlwrap-0.37'
make[2]: Entering directory `/home/oracle/rlwrap-0.37'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/share/rlwrap" || /bin/mkdir -p "/usr/share/rlwrap"
/bin/mkdir -p '/usr/share/rlwrap/filters'
 /usr/bin/install -c -m 644  filters/README filters/RlwrapFilter.pm filters/RlwrapFilter.3pm filters/count_in_prompt filters/pipeto filters/logger filters/null filters/unbackspace filters/pipeline filters/ftp_filter filters/history_format filters/simple_macro filters/template filters/scrub_prompt filters/paint_prompt filters/censor_passwords filters/listing '/usr/share/rlwrap/filters'
/bin/mkdir -p '/usr/share/rlwrap/completions'
 /usr/bin/install -c -m 644  completions/testclient completions/coqtop '/usr/share/rlwrap/completions'
make  install-data-hook
make[3]: Entering directory `/home/oracle/rlwrap-0.37'
chmod a+x /usr/share/rlwrap/filters/*
make[3]: Leaving directory `/home/oracle/rlwrap-0.37'
make[2]: Leaving directory `/home/oracle/rlwrap-0.37'
make[1]: Leaving directory `/home/oracle/rlwrap-0.37'

6. Remember to set an alias for the program sqlplus

oracle@ubuntu-server:~/rlwrap-0.37$ vi ~/.bashrc

… and add a row:

alias sqlplus='/usr/bin/rlwrap sqlplus'

… as shown in the picture:

Add sqlplus alias for rlwrap utility
Add sqlplus alias for rlwrap utility

After re-logon account under which you were logged in compiling (and for whom do you show the SQL*Plus), you should be able to use the arrows “up /downscroll through the history of performed commands run from within SQL*Plus.

Post to Twitter

1 Comment

  1. Raj Joseph

    Reply

    Superb…Works for me
    Ubuntu 10.10
    Oracle 11.2.0.1 client
    Oracle 10.2.0.5 Database in Oracle VirtualBox

Leave a comment

Your email address will not be published. Required fields are marked *