Tuesday Jan 24, 2012

Getting History from SQLPlus using Linux

A colleague of mine just asked me how do you get history in SQLPlus on Linux the same way you get by default in windows, e.g. when you press the up key you see the previous commands executed. I have never really given it much thought in the past, but there must be a way. After a quick Google search I found a solution. This blog is really for my future reference as the examples I found on the net required a bit of thought.

The post assumes you are using RedHat or OEL, It will work for other Linux OS but you will need to source the right application. I'm installing on OEL 5.7 64 bit.

The key behind this solution is the utility call rlwrap which is a read line wrapper. It maintains a separate input history which can be edited.

  1.  Login to you Linux machine as the root user

  2. Download the rlwrap utility using the appropriate link below and save it to a staging area on the Linux machine:
    rlwrap 32Bit
    rlwrap 64Bit

  3. From the staging area install the rlwrap utility, e.g.:

    rpm -ivh rlwrap-0.37-1.el5.x86_64.rpm

  4. Connect as the oracle user (or the user you connect to SQLPlus)

  5. Edit the .bashrc file ($HOME/.bashrc) and add the following line in the aliases section.

    alias sqlplus="rlwrap sqlplus"

  6. Initialize the .bashrc file with the following command

    . .bashrc

  7. Login to SQLPlus and history should be enabled

    sqlplus scott/tiger@orcl

    SQL*Plus: Release 11.2.0.2.0 Production on Wed Jan 25 04:07:40 2012

    Copyright (c) 1982, 2010, Oracle.  All rights reserved.


    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options

    SQL> select count(*) from emp;

      COUNT(*)
    ----------
            15


    Press the up key

    SQL> select count(*) from emp;

Now you are done. Enjoy



About

Discussions and Examples using Oracle Fusion Middleware. Some image links are broken when using Firefox, Safari, and Chrome. If you want to see the full image please use IE.

Twitter:@james8001

tumblr hit counter vistors, thanks for your support

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today