sql*plus does not have a command history function under Linux and Unix.
Lately I listened to Tom Kyte at one of his seminars he delivered in September in Zurich. He used a virtual Linux machine and had a command history for his sql*plus obviousely.
He told us that he used a utility called rlwrap for this.
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.
I simply had to get it!
And I think that this is worth sharing it.
Here is how it works and how you can get it too.
You can download the sources for the rpm for rlwrap from
here. The most recent version I could find is version 0.26.
There you also find a README and the manpage for rlwrap.
After downloading and unpacking the tar.gz I ran as root (#)
./configure
make
make check
make install
and that was it.
Now I could call sqlplus this way:
$ rlwrap sqlplus user/password@sid.
Finally I create an alias
alias sqlp =”rlwrap sqlplus”
(pls see Laurent Schneider’s comment on this post about alias sqlplus!)
Now I can simply call sqlplus as I always have done
and have a commend history with the ↑ and ↓ keys on my keyboard.
This will put an end to the stoneage habits we have all got used to too much!
alias sqlplus=”rlwrap sqlplus”
this I would avoid. rlwrap does not support non-interactive mode (echo xxx | sqlplus), is not an oracle support tool, and crashes occasionnaly.
Personnaly I do
alias q=”rlwrap sqlplus”
so that I can always use sqlplus to run important script, and keep rlwrap for not-productive stuff.
cheers
laurent
Hi,
the first variant is ok:
$ alias sqlplus=”rlwrap sqlplus”
If you want history, then you run alias:
$ sqlplus
To run command instead of the alias you add backslash:
$ \sqlplus
cheers,
Mitja
Hi Laurent,
cool! Thanks for pointing this out!
=;-)
I don’t believe it! This morning I tried to remember the name of a tool I once saw somebody using at an Oracle University class.
)
Ten minutes later, when I was browsing through google reader I saw this post on your blog
Hi HPFUCHS,
there must be some kind of interconnect between us, what do you say?
It’s chool män!
=;-)
i saw it also during an oracle 11g event and was very interested. here you can find my article http://bd-home.net/archives/10-Command-history-and-keyword-completion-in-SQLPlus.html and here http://www.linuxification.at/rlwrap_ext.html you find a oracle keyword list including some shell scripts.
Hi BD,
this is also very interesting!
Thanks for pointing it out.
Which 11g event were you at anyway?
Thanks,
LUTZ
=;-)
I’ve had pretty much this exact advice in an article on my website since 2005! Tom actually got his first taste of rlwrap as a result of my original article… just thought I’d mention it.
Hi dizwell,
I just wanted to share what I like to use because I think that knowlege is not private property and should be shared.
I did not inquire about the inventor.
I found out that a lot of people use rlwrap
and a lot do not even know about it.
So what is the problem?
=;-)
Hi dizwell,
I just received this from Ausria:
Hi Lutz!
I am that guy who gave that event were user BD heard about rlwrap. I found out about it 18 months ago and use it very often since then. I produced some additional files to use name completion with the tab key.
It is quite nice to have a tool completing names of DBA_ views, parameters and so on. I put those files on my website for download (for free, of course). The link to the english web page is:
http://www.linuxification.at/rlwrap_ext.html.en
have fun
Thanks a lot for sharing this invaluable info. Finally sqlplus can be more friendly
Thanks a lot for this. I needed precisely this in my shellscripts. Like:
“rlwrap cat >> filename”
How can we prevent passwords from ending up in the .sqlplus_history file?
I tried this but the password still goes into history:
rlwrap -a”Enter Password:” sqlplus /nolog
On HP-UX, one can call sql*plus from ied
ied sqlplus sunil/bhola@DB1
I got this interesting links from my friend. Really nice blog In my opinion making ebook about it and selling it is a really nice idea. Check my site out about at
Hi Lutz,
By any chance do you have a copy of the
http://www.linuxification.at/rlwrap_ext.html.en
as it seems is no longer online.
Cheers,
Dani