在 Linux的 sqlplus中运行 SQL语句之后,想用上下键把历史命令找出来,这样是linux系统默认是不支持的。

 如何像windows里的cmd窗口的sqlplus一样能上下翻历史命令呢?

可以使用 rlwrap工具实现这个功能


1.下载 rlwrap工具


 

2.安装 rlwrap

[root@server122 oracle]# tar -zxvf rlwrap-0.37.tar.gz

[root@server122 rlwrap-0.37]# ./configure

[root@server122 rlwrap-0.37]# make

[root@server122 rlwrap-0.37]# make install

--查看 rlwrap命令

[root@server122 rlwrap-0.37]# rlwrap

Usage: rlwrap [options] command ...

 

Options:

  -a[password:]              --always-readline[=password:]

  -A                         --ansi-colour-aware

  -b                  --break-chars=

  -c                         --complete-filenames

  -C                 --command-name=

  -D  <0|1|2>                --history-no-dupes=<0|1|2>

  -f        --file=

  -g                 --forget-matching=

  -h                         --help

  -H                   --history-filename=

  -i                         --case-insensitive

  -I                         --pass-sigint-as-sigterm

  -l                   --logfile=

  -n                         --no-warnings

  -N                         --no-children

  -o                         --one-shot

  -O                 -->

  -p[colour]                 --prompt-colour[=colour]

  -P                  --pre-given=

  -q                  --quote-characters=

  -m[newline substitute]     --multi-line[=newline substitute]

  -r                         --remember

  -R                         --renice

  -v                         --version

  -s                      --histsize= (negative: readonly)

  -S                 --substitute-prompt=

  -t                   --set-term-name=

  -w                      --wait-before-prompt= (msec, <0  : patient mode)

  -z         --filter=

 

bug reports, suggestions, updates:

~hlub/uck/rlwrap/

 

3.使用 rlwrap

[oracle@server122 ~]$ rlwrap sqlplus "/as sysdba"

SQL> show sga

 

Total System Global Area 2.5770E+10 bytes

Fixed Size                  2142928 bytes

Variable Size            2852130096 bytes

Database Buffers         2.2901E+10 bytes

Redo Buffers               14630912 bytes

 

--此时用上下键功能可以就可像 windows里一样,可以上下翻命令了

SQL> show sga

 

4.设置 sqlplus别名

为了 sqlplus使用方便,让 sqlplus默认在 rlwrap方式下运行,可以设置一个别名

[oracle@server122 ~]$ pwd

/home/oracle

 

[oracle@server122 ~]$ vi .bash_profile

alias sqlplus='rlwrap sqlplus' #添加此内容

 

--使之生效,或是重新登录 oracle用户

[oracle@server122 ~]$ source .bash_profile

 

--用 type sqlplus验证,如果显示下面的信息证明 alias设置成功

[oracle@server122 ~]$ type sqlplus

sqlplus is aliased to `rlwrap sqlplus'

 

[oracle@server122 ~]$ sqlplus "/as sysdba"

SQL> show sga

 

Total System Global Area 2.5770E+10 bytes

Fixed Size                  2142928 bytes

Variable Size            2852130096 bytes

Database Buffers         2.2901E+10 bytes

Redo Buffers               14630912 bytes

 

--同样上下翻可以再显历史命令

SQL> show sga

 

注意:

alias定义中使用的是单引号,而不是 TAB上面的那个, /home/oracle/是 oracle用户的主目录。

 

问题:

在安装rlwrap时,如报下面的错误:


[root@nticket1 rlwrap-0.37]# ./configure

......

OPENPTY

configure: checking for pty ranges...

checking for tgetent... no

checking for tgetent in -lcurses... no

checking for tgetent in -lncurses... no

checking for tgetent in -ltermcap... no

configure: WARNING: No termcap nor curses library found

checking for readline in -lreadline... no

configure: error: 


You need the GNU readline library(ftp://ftp.gnu.org/gnu/readline/ ) to build

this program!


解决方法 

安装下面包

libtermcap-devel 

readline-5.1-1.1
readline-devel-5.1-1.1 


©著作权归作者所有:来自51CTO博客作者zddbj的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 更改sqlplus命令提示符的样式
  2. Exa – 替代ls命令的超好用工具
  3. 教你在 Linux 中使用 lsusb命令 显示有关USB设备信息
  4. 迈普交换机关闭分屏显示
  5. 教你使用 lsblk命令 列出系统中的块设备
  6. Python中的3D绘图命令
  7. Office 365邮件自动转发管理设置
  8. kvm虚拟机日常操作命令梳理
  9. Redis日常操作命令小结

随机推荐

  1. EditText对行光标默认第一行问题
  2. Android 中的 R.class,减小 Apk 包大小
  3. Android支持的媒体格式
  4. android仿京东商城例子
  5. 使用ContentProvider时出现SecurityExcep
  6. android快捷卸载第三方应用
  7. android socket客户端app
  8. Android——ScrollView
  9. android > styles
  10. android控件相对布局