Chinaunix首页 | 论坛 | 博客
  • 博客访问: 255366
  • 博文数量: 54
  • 博客积分: 2668
  • 博客等级: 少校
  • 技术积分: 560
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-06 01:08
文章分类

全部博文(54)

文章存档

2011年(14)

2010年(14)

2009年(26)

分类:

2009-05-06 09:11:21

write by Linc Zhou

[Oracle] 利用Uniread 解决 Linux下的SQL*Plus 命令行历史回调功能

大家知道, Windows 平台命令行中的 SQL*Plus 有命令行历史回调的功能,SQL*Plus工具下面,可以利用键盘的"向上向下"箭头键对命令行的进行回调.而在Linux上则没有该功能(虽然 Shell 可以做到这一点,但是 SQL*Plus 不可以). 而该功能对于CLI爱好者来说几乎是不可缺的,不知道为什么 Oracle 不把这个功能加进来.不得而知了.

一些SQL*Plus 的替代产品(gqlplus 以及 yasql )具备command-line editing Command history的功能, 但是这些产品的开发进度较慢--有的甚至已经停止了更新.

在网络上闲逛的时候, 发现了一个在Linux下面的解决办法.

该工具叫做 uniread - ) ,熟悉Linux下变成的朋友可能看到这个名字已经想起了一些东西:readline . 不错,该工具就是利用GNUreadline库来完成我们的需求的.

我们先看一下对该工具的介绍:

uniread - universal readline

uniread adds readline (line editing, command history, etc.) support to anyexisting interactive command-line program. You can use this to add support to annoying programs which do not provide it built-in (a good example isOracle's sqlplus, or jython) or to easily add it to your own programs.

可以看出,该工具可以对任何既有的交互命令行程序都可提供完备的readline支持.

从该站点下载源程序.目前的稳定版本是1.01.

在安装该工具之前系统必须安装好Perl, 此外还必须要三个工具包:

GNU readline

Term::ReadLine::Gnu

还可以到 这个页面下去下载

IO::Tty

下载后,首先解压缩:

# tar -xzvf readline-4.3.tar.gz

进入进入到该目录中编译并安装:

# ./configure

# make

# make install

后面两个的安装: tar -zxvf ...... 进入到该目录中:

# perl Makefile.pl

# make

# make install

都安装完了之后,进行 uniread 的安装:

#tar -xzvf uniread-1.01.tar.gz

#cd uniread-1.01

#./configure

#make

#make install


: 以上的命令行操作所在绝对路径为了方便而省略,你的环境肯定会和我的不同,此外,建议使用普通用户编译,然后用 root 进行 make install .


都安装完了之后切换到Oracle用户下:

$ uniread sqlplus /nolog

输出类似如下:


[uniread] Loaded history (12 lines) //我的已经运行一次了,uniread 缓冲了12history

SQL*Plus: Release 11.1.0.6.0 - Production on Sun Mar 29 15:18:37 2009

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

查看unireadManual:

$man uniread

你可以做个sqlplus 的别名 ,进入oracle 的家目录,修改.bashrc 文件,添加一条记录,alias sqlplus = 'uniread sqlplus',这样uniread的使用是透明的,是不是很方便了? 不要忘了:这个工具是有通用性的,不止是 SQL*Plus 可以这样用,其他类似的命令行程序也能如此的.

FAQ

如果要删除命令行历史,可以简单的用如下操作即可:

[oracle@Linc oracle]$ echo ''>.uniread/sqlplus

[oracle@Linc oracle]$

[oracle@Linc oracle]$ ls -ltr .uniread/

total 4

-rw------- 1 oracle oracle 1 Oct 31 15:57 sqlplus

[oracle@Linc oracle]$

[oracle@Linc oracle]$ sqlplus /nolog

[uniread] Loaded history (1 lines)

SQL*Plus: Release 11.1.0.6.0 - Production on Sun Mar 29 15:18:37 2009

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

SQL>

阅读(1336) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~