1.rlwrap工具的下載及安裝
rlwrap工具的下載及安裝方法可以參考
rlwrap for Command Line History and Editing in SQL*Plus and RMAN on Linux
2.rlwrap工具的參數(shù)說明
通過上述步驟安裝好rlwrap工具以后妆丘,只能實(shí)現(xiàn)命令歷史記錄的上下翻找功能,而無法實(shí)現(xiàn)如下幾個(gè)功能
命令歷史記錄的去重功能
SQL語句中的關(guān)鍵字自動(dòng)補(bǔ)全功能
文件目錄的自動(dòng)補(bǔ)全功能
要實(shí)現(xiàn)上述三個(gè)功能,就需要增加額外的命令行參數(shù)來實(shí)現(xiàn)捂敌,具體參數(shù)及描述如下
-D2:此參數(shù)可以實(shí)現(xiàn)命令歷史記錄的去重功能难咕,在SQL PLUS中輸入n次select * from dual;語句并多次執(zhí)行之后型宙,在shell ~/.sqlplus_history
文件中只保存一條記錄匀奏,這樣可以有效的壓縮sqlplus歷史文件的大小
-c: 此參數(shù)可以實(shí)現(xiàn)目錄及文件路徑的自動(dòng)補(bǔ)全功能蛔翅,在SQL PLUS中輸入shell ! vi /etc/sec
命令后瓶殃,可以通過tab鍵實(shí)現(xiàn)路徑補(bǔ)全功能
-i:此參數(shù)可以實(shí)現(xiàn)在命令行關(guān)鍵字自動(dòng)補(bǔ)全功能時(shí)充包,忽略大小寫。但在文件路徑的自動(dòng)補(bǔ)全中遥椿,仍然在大小寫區(qū)分 的基矮。
-f:此參數(shù)后面跟一個(gè)關(guān)鍵字補(bǔ)全列表文件,可以在SQL PLUS中實(shí)現(xiàn)關(guān)鍵字的查找補(bǔ)全功能冠场。
根據(jù)上述參數(shù)的含義家浇,我們可以新建一個(gè)alias到shell的配置文件中,如下所示
alias sl='rlwrap -D2 -irc -b'\''"@(){}[],+=&^%#;|\'\'' -f ~/work/oracle/tpt/setup/wordfile_11gR2.txt sqlplus sys/oracle@linux01/lin11g as sysdba'
這樣就可以實(shí)現(xiàn)上面所說的那些功能了碴裙。
3. 關(guān)鍵字補(bǔ)全列表文件的構(gòu)建
大部分人員認(rèn)為只要在SQL PLUS文件中實(shí)現(xiàn)select钢悲、update、delete舔株、insert莺琳、from等幾個(gè)少量的關(guān)鍵字的自動(dòng)補(bǔ)全功能就已經(jīng)很了不起來,可以滿足需求载慈,那還要構(gòu)建關(guān)鍵字補(bǔ)全列表作什么呢惭等?這里的構(gòu)建不是簡單的幾個(gè)關(guān)鍵字而已,我還想把數(shù)據(jù)庫表名、數(shù)據(jù)庫關(guān)鍵字列表、數(shù)據(jù)庫包名.函數(shù)名露懒、字段名、數(shù)據(jù)庫參數(shù)等等都要包含進(jìn)去秤茅,要實(shí)現(xiàn)這樣的構(gòu)建可以通過spool filename
+ sql語句來實(shí)現(xiàn),具體的sql腳本為wordfile_11gR2.sql
和wordfile_12cR1.sql
童叠。詳細(xì)的sql語句如下
set lines 300 trimspool on pages 0 head off feedback off termout off
SELECT DISTINCT name FROM (
select lower(keyword) name from v$reserved_words union all
select upper(table_name) from dict union all
select upper(column_name) from dict_columns union all
-- select object_name from dba_objects union all
select upper(object_name||'.'||procedure_name) from dba_procedures union all
-- select '"'||table_name||'".'||column_name from dba_tab_columns union all
select ksppinm from x$ksppi union all
select name from v$sql_hint
)
WHERE length(name) > 2
ORDER BY 1
4.相關(guān)參考文件
相關(guān)的文件如下
- tpt/setup/README_rlwrap.txt
- tpt/setup/wordfile_11gR2.sql
- tpt/setup/wordfile_12cR1.sql
- tpt/setup/wordfile_11gR2.txt
- tpt/setup/wordfile_12cR1.txt