在sqlplus中實現命令的上翻下翻功能

jolly10發表於2012-07-17

在linux下使用Oracle的sqlplus時,預設情況下箭頭鍵不起到左右移動游標,上下翻動命令的作用。導致使用很不方便。這裡我要介紹一 個小工具軟體rlwrap(軟體解除安裝地址:),這是一個“readline wrapper”工具,可以使用左右箭頭在一行中左右移動游標,還可以用上下箭頭來上翻和下翻回撥命令,甚是好用。

下載地址:

[@more@]

我用的是0.24原始碼版。安裝和簡單:
./configure
make
make install

其他一些安裝的情況比如用非root使用者安裝,看看readme和install檔案就行了,也非常簡單。(這個我沒有測試過,大家動手學習吧!)
而且現在已經有rpm版的了。安裝後在Oracle使用者的.bash_profile檔案中加上兩句話:
alias sqlplus="rlwrap sqlplus"
alias rman="rlwrap rman"
重新用Oracle使用者登入或執行. /home/oracle/.bash_profile,使修改生效。下面就可以在sqlplus和rman中按想象的方式使用箭頭鍵了。

我的測試過程:

將rlwrap-0.37.tar.gz包上傳至Linux伺服器。

[root@study setup]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
100% 245 KB 245 KB/s 00:00:01 0 Errors

將rlwrap-0.37.tar.gz包解壓

[root@study setup]# tar -zxvf rlwrap-0.37.tar.gz
rlwrap-0.37/
rlwrap-0.37/completions/
rlwrap-0.37/completions/testclient
rlwrap-0.37/completions/coqtop
rlwrap-0.37/doc/
rlwrap-0.37/doc/rlwrap.man.in
rlwrap-0.37/doc/Makefile.am
rlwrap-0.37/doc/Makefile.in
rlwrap-0.37/filters/

.......

進入到解壓後目錄

[root@study setup]# cd rlwrap-0.37

執行編譯,安裝,過程如下:

[root@study rlwrap-0.37]# ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
.......
config.status: executing depfiles commands

Now do:
make (or gmake) to build rlwrap
make check for instructions how to test it
make install to install it

[root@study rlwrap-0.37]# make
make all-recursive
make[1]: Entering directory `/home/setup/rlwrap-0.37'
Making all in doc
make[2]: Entering directory `/home/setup/rlwrap-0.37/doc'
sed -e 's#@DATADIR@#/usr/local/share#' rlwrap.man > rlwrap.1
make[2]: Leaving directory `/home/setup/rlwrap-0.37/doc'
Making all in src
make[2]: Entering directory `/home/setup/rlwrap-0.37/src'
.......
make[2]: Entering directory `/home/setup/rlwrap-0.37'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/setup/rlwrap-0.37'
make[1]: Leaving directory `/home/setup/rlwrap-0.37'
[root@study rlwrap-0.37]#
[root@study rlwrap-0.37]# make install
Making install in doc
make[1]: Entering directory `/home/setup/rlwrap-0.37/doc'
.......
make[1]: Leaving directory `/home/setup/rlwrap-0.37'

切換至oracle使用者,修改配置檔案.bash_profile

[oracle@study ~]$ vi .bash_profile
在檔案最後新增
alias sqlplus="rlwrap sqlplus"
alias rman="rlwrap rman"

儲存並是配置生效

[oracle@study ~]$ source .bash_profile


這時,我們在登入sqlplus 就是可以使用左右上下鍵了。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/271283/viewspace-1058832/,如需轉載,請註明出處,否則將追究法律責任。

相關文章