Database

How to enables command-line history in SQL*PLUS

oracle-database SQL*PLUS (sqlplus) does not let you press ↑ “up” or ↓ “down” to browse previous commands. You can inspect only one previous command. This can be inconvenient because earlier commands must be typed again. On Linux, rlwrap intercepts user input to SQL*PLUS and saves it in a history so that users can browse earlier commands using ↑ “up” or ↓ “down”.

Installing and using rlwrap with SQL*PLUS

  1. Install EPEL repo****CentOS 5 rpm -ivh http://mirror1.ku.ac.th/fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm CentOS 6 rpm -ivh http://mirror1.ku.ac.th/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

  2. Install rlwrapyum install rlwrap

  3. Edit the oracle user’s bash_profile so that rlwrap is used every time.

    su - oracle
    vi .bash_profile

      Add the following command.

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

When using sqlplus, you can now press ↑ “up” or ↓ “down” to browse previous commands, or “Crtl + r” to search the history faster (as in Bash).

EOF.← Back to articles