在Linux下使用sqlplus历史回调功能

/*

 *source: http://www.linuxdiyf.com/viewarticle.php?id=59276

 */

当在Linux Shell中运行SQL*Plus的时候,并不提供浏览历史命令行的功能。相反的,在Windows操作系统上,当在DOS命令窗口中运行 SQL*Plus的时候,可以使用向上,向下键来跳回之前已经执行过的SQL语句。你可以 根据需要修改他们,然后按[Enter]重新提交执行。

为了在Linux中达到同样的目的,你可以安装rlwrap,这个程式本身是个Shell,可以运行任何你提供给它的命令包括参数,并添加命令历史浏览功 能。 The rlwrap program is under the GPL license。

1:安装
rlwrap-0.28.tar.gz下载地址:http://utopia.knoware.nl/~hlub/uck/rlwrap/

1):解压缩安装文件
[oracle@Channel-MQ3 ~]$gunzip rlwrap-0.28.tar.gz
[oracle@Channel-MQ3 ~]$tar xvf rlwrap-0.28.tar

2):切换到root用户,执行下面的命令
[root@Channel-MQ3 ~]# cd /home/oracle/rlwrap-0.28
[root@Channel-MQ3 rlwrap-0.28]# ls
aclocal.m4 completions configure INSTALL README TODO
AUTHORS config.h configure.ac Makefile src tools
bash30-005.patch config.h.in COPYING Makefile.am stamp-h1
BUGS config.log distribution Makefile.in test
ChangeLog config.status doc NEWS test.log
[root@Channel-MQ3 rlwrap-0.28]#./configure
[root@Channel-MQ3 rlwrap-0.28]#make
[root@Channel-MQ3 rlwrap-0.28]#make install

2:使用
$ rlwrap [-options]
[oracle@Channel-MQ3 ~]$ which rlwrap
/usr/local/bin/rlwrap
[oracle@Channel-MQ3 ~]$ rlwrap sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jul 18 10:31:11 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select * from v$sga;

NAME VALUE
-------------------- ----------
Fixed Size 1219856
Variable Size 121635568
Database Buffers 310378496
Redo Buffers 7168000

-- 使用向上键调回最后执行的命令,按[Enter]重新执行或修改后按[Enter]执行
SQL> select * from v$sga;

NAME VALUE
-------------------- ----------
Fixed Size 1219856
Variable Size 121635568
Database Buffers 310378496
Redo Buffers 7168000

另外rlwrap还有很多选项可以设置
eg:
−l, −−logfile file
Append command’s output (including echo’ed user input) to file (creating file when it doesn’t exist).

测试如下
[oracle@Channel-MQ3 ~]$ rlwrap -l benbotest.log sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jul 18 10:34:50 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@Channel-MQ3 ~]$ cat benbotest.log

[rlwrap] Wed Jul 18 10:34:50 2007
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jul 18 10:34:50 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@Channel-MQ3 ~]$

当然,如果嫌每次敲rlwrap不爽,可以在/etc/profile或者自己的~/.bashrc里面添加alias sqlplus='rlwrap sqlplus'。其他发行版的朋友可以选择rpm包或者干脆从源码自己编译。

其它选择参考manpage。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值