如何让sql plus有记忆?
在linux或者unix里面,slplus的运行一般都是不能使用记忆功能,即不能使用上下左右键,这是一件很让人痛苦的事情。怎么办?开源工作者又贡献了一把!
首先,声明我是在使用的时候遇到这种让人头疼的问题,于是在网络中搜出了解决之道,本文大部分是参考fenng大师的文章,然后自己实践成功后发的,fenng的文章源地址是:http://www.dbanotes.net/Oracle/uniread-howto.htm。另外,在此我也推荐一个有关oracle的问题的解决之道的好方法,你只需要敲入了的问题的关键字,然后搜索就可以了,我觉得目前80%的oracle问题,你在这里都能找到答案。这个神秘的地方,神秘的搜索,当然是google了,但是我给它加了点元素,把这个链接收藏起来吧:http://www.google.cn/custom?domains=itpub.net,就是它了,下面言归正传。
该工具叫做 uniread - http://sourceforge.net/projects/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支持。从该站点下载源程序.目前的稳定版本是1.01。
在安装这个软件之前,你的系统必须安装好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/)
将这几个工具下载好,也下载好uniread,将他们解压,命令是tar -xzf *.tar.gz,然后以下顺序执行以下命令,来安装这些软件:
1、安装 readline-5.2
cd readline-5.2
./configure
make
make install
2、安装 Term-ReadLine-Gnu-1.16
cd Term-ReadLine-Gnu-1.16
perl Makefile.PL
make
make install
3、安装 IO-Tty-1.07
cd IO-Tty-1.07
perl Makefile.PL
make
make test
make install
4、安装 uniread-1.01
cd uniread-1.01
perl Makefile.PL
make
make install
建议:
使用普通用户(oracle)执行配置和编译(./configure, perl Makefile.PL, make , make test ),使用root执行安装(make install)。
都安装完了之后切换到Oracle用户下:
$ uniread sqlplus /nolog,输出类似如下:
[uniread] Loaded history (12 lines) //我的已经运行一次了,uniread 缓冲了12行history
SQL*Plus: Release 10.1.0.2.0 - Production on Sat Mar 6 00:23:05 2004
Copyright (c) 1982, 2004, Oracle. All rights reserved.
SQL>
查看uniread的Manual:$man uniread。你可以做个sqlplus 的别名 ,uniread的使用是透明的,是不是很方便了? 不要忘了:这个工具是有通用性的,不止是 SQL*Plus 可以这样用,其他类似的命令行程序也能如此的。
FAQ
如果要删除命令行历史,可以简单的用如下操作即可:
[oracle@FOO oracle]$ echo ''>.uniread/sqlplus
[oracle@FOO oracle]$ ls -ltr .uniread/
total 4
-rw------- 1 oracle oracle 1 Oct 31 15:57 sqlplus
[oracle@FOO oracle]$ uniread sqlplus
[uniread] Loaded history (1 lines)
SQL*Plus: Release 9.2.0.4.0 - Production on Sun Oct 31 15:58:29 2004
.....