在 Windows 平台 命令行中的 SQL*Plus 有命令行历史回调的功能,在SQL*Plus工具下面,可以利用键盘的”向上向下”箭头键对命令行的进行回调.而在Linux上则没有该功能(虽然 Shell 可以做到这一点,但是 SQL*Plus 不可以).
下面介绍在Linux下面的解决办法:
该工具叫做 uniread -,熟悉Linux下变成的朋友可能看到这个名字已经想起了一些东西:readline . 不错,该工具就是利用GNU的readline库来完成我们的需求的.
uniread – universal readline
– adds full readline support (command editing, history, etc.) to any existing
interactive command-line program. Common examples are Oracle’s sqlplus or jython. uniread will work
on any POSIX platform with Perl.
可以看出,该工具可以对任何既有的交互命令行程序都可提供完备的readline支持.
在安装该工具之前系统必须安装好Perl, 此外还必须要三个工具包:
GNU readline
<http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html>
Term::ReadLine::Gnu
<http://search.cpan.org/dist/Term-ReadLine-Gnu/>
IO::Tty
<http://search.cpan.org/dist/IO-Tty/>
其中GNU readline 上面的网页在我的机器上打不开(不可访问?),如果你也是同样情况,可以到
<http://www.gnu.org/directory/readline.html> 这个页面下载.
readline可以使用yum安装,也可以使用tar包编译安装
下面两个安装需要用到CPAN shell:
shell> perl -MCPAN -e shell
cpan[1]> install Term::ReadLine::Gnu
cpan[2]> install IO::Tty
都安装完了之后,进行 uniread 的安装:
shell> wget -c http://sourceforge.net/projects/uniread/files/latest/download
shell>tar -xzvf uniread-1.01.tar.gz
shell> cd uniread-1.01
shell> perl Make.PL
shell> make
shell> make install
都安装完了之后切换到Oracle用户下:
shell> uniread sqlplus /nolog
输出类似如下:
[uniread] Loaded history (12 lines) //已经运行一次了,uniread 缓冲了12行 history
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 6 14:09:03 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL>查看uniread的Manual:
shell> man uniread
你可以做个 SQL*Plus 命令的别名 ,在家目录的.bash_profile中加入alias sqlplus=”uniread sqlplus”,这样使用sqlplus直接就可以调用历史命令了。
uniread 的使用是透明的,是不是很方便了? 不要忘了:这个工具是有通用性的,不止是 SQL*Plus 可以这样用,其他类似的命令行程序也能如此的.
FAQ
如果要删除命令行历史,可以简单的用如下操作即可:
[oracle@FOO ~]$ echo ”>.uniread/sqlplus
[oracle@FOO ~]$
[oracle@FOO ~]$ ls -ltr .uniread/
total 4
-rw——- 1 oracle oracle 1 Oct 31 15:57 sqlplus
[oracle@FOO ~]$
[oracle@FOO ~]$ uniread sqlplus
[uniread] Loaded history (1 lines)
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 6 14:29:04 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
……
参考信息
uniread – <http://sourceforge.net/projects/uniread/>
GNU readline – <http://www.gnu.org/directory/readline.html>
Linenoise – A small self-contained alternative to readline and libedit
Google – <http://www.google.com>