Tuesday, March 17, 2009

SQL*Plus command history on Mac OS X

Anyone who has tried and use SQL*Plus on Unix would have seen that its quite frustrating since it does not have a command history function under Linux and Unix. When you try to use the ‘up’ key, you get something like this:
However there is a utility called rlwrap that can help us fix this problem. rlwrap is a readline wrapper for shell commands which uses input from the controlling terminal. It adds a persistent input history for each command and supports user-defined completion.

Here are the steps to install rlwrap on Mac OS X:

1. Download Macports from http://darwinports.com/ (If you don't have it already)
2. Install macports.
3. Update macports. Go to /opt/local/bin and type the following:

sudo ./port -d selfupdate

4. Install rlwrap with the following command (You will see it will install some dependencies too):

sudo ./port install rlwrap

5. Add the following line to your .bash_profile:

alias sqlplus='/opt/local/bin/rlwrap sqlplus'

6. Launch SQL*plus as usual and use rlwrap to access your sql history!

No comments: