解決Linux下SQL*Plus曆史回調功能

來源:互聯網
上載者:User

大家知道, 在 Windows 平台 命令列中的 SQL*Plus 有命令列曆史回調的功能,在SQL*Plus工具下面,可以利用鍵盤的"向上向下"方向鍵對命令列的進行回調.而在Linux上則沒有該功能(雖然 Shell 可以做到這一點,但是 SQL*Plus 不可以). 而該功能對於CLI愛好者來說幾乎是不可缺的,不知道為什麼 Oracle 不把這個功能加進來.不得而知了.
  
  一些SQL*Plus 的替代產品(如 gqlplus 以及 yasql )具備command-line editing 和Command history的功能, 但是這些產品的開發進度較慢--有的甚至已經停止了更新.
  
  (參見: gqlplus - http://sourceforge.net/projects/gqlplus 以及 yasql - http://sourceforge.net/projects/yasql/ 等 SQL*Plus 替代工具 ).
  
  在網路上閑逛的時候, 發現了一個在Linux下面的解決辦法.
  
  該工具叫做 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/
  其中GNU readline 上面的網頁在我的機器上打不開(不可訪問?),如果你也是同樣情況,可以到 http://www.gnu.org/directory/readline.html 這個頁面下載.
  
  下載後,首先解壓縮:
  
  # 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 緩衝了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]$
  [oracle@FOO oracle]$ ls -ltr .uniread/
  total 4
  -rw-------  1 oracle  oracle     1 Oct 31 15:57 sqlplus
  [oracle@FOO oracle]$
  [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

本文轉自:http://oracle.chinaitlab.com/PLSQL/38591.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.