how to edit command-line in sqlplus and rman (unix case)

Have you ever heard about rlwrap utility which brings the power of GNU readline library to sqlplus? It means that with the help of rlwrap we are able not only to edit command-line but also to do a search through previous commands and to use words completion during edit.

All you need is to install rlwrap (if you don't have root access, you still able to install it locally in your $HOME) and define a couple of aliases somewhere in your .bashrc:

alias sqlplus='rlwrap -b "" -f $HOME/sql.dict sqlplus'
alias rman='rlwrap -b "" -f $HOME/sql.dict rman'

File $HOME/sql.dict can contain a words for which you want to use 'word completion' feature. For example: select, v$session, configure, count(*). After that, while starting to type in slplus 'co' and pressing <Tab> we immediately get 'count(*)'.

Option -b (or --break-chars) defines which characters are treated as word delimiters in file sql.dict. By default delimiters are: (){}[].,+-=&^%$#@\;|' We don't need such a big set (especially we don't need '$' as word delimiter), so we just specify an empty set. In such case only \r,\n and space will be treated as delimiters.

Voila. Happy editing in sqlplus! For the list of available editing features use 'man readline' in your unix shell.


By the way, if you use vim as your default editor in sqlplus and want to enable word autocompletion in vim too, then you probably will like another my tiny article 'how to use vim in sqlplus'.