[20141024]使用emacs連接配接使用oracle資料庫.txt
--前一陣子跟别人學習了使用emacs連接配接資料庫.自己做一個簡單記錄.
1.首先需要安裝emacs.這個步驟忽略.
2.使用emacs打開檔案.
--我使用它在指令行沒有檔案.當然也可以有檔案.
--首先學習如何退出,+x,+c,以免出錯不知道如何出來,我不會使用它來編輯檔案.
-- +x,+s,儲存檔案.
3.連接配接oracle資料庫:
有兩種方法連接配接,實際上都是一樣的調用sqlplus指令.
方法1: x,接着輸入shell,出現shell提示符号.打入sqlplus指令就可以使用了.
方法2:
-- x 接着輸入sql-oracle,打入sql-o按鍵可以使用指令補全功能的.
--根據提示輸入user,pass,database等資訊.但是不能使用scott/tiger@orcl這樣的格式.資料庫格式可以使用ezconnect格式.
4.連接配接上後出現2個分離的螢幕.
--方法2會出現兩個分離的視窗.
--按ctrl+x 1 關閉上面的螢幕.這樣就好像putty登入linux,進入sqlplus的界面.3個也可以.
--現在開始使用了.
--設定linesize避免折行.避免sqlplus輸出出現折行情況:
set linesize 2000
--打入 x toggle-truncate-lines,關閉emacs的折行功能.好像再執行一個傳回原樣.
--也可以輸入在.emacs檔案中:(我不懂這些)
(setq-default truncate-lines t)
(setq truncate-partial-width-windows nil) ;; for vertically-split windows
5.打入指令就可以了.可以上下移動重複執行指令.
6.編輯想換行可以使用+j ,這樣可以指令可以重複使用。如果你使用回車,再次執行會報錯,使用+j寫sql語句就沒有問題.
7.如何退出:
+x ctrl+s 儲存檔案.
+x ctrl+c 退出.
--這樣可以把操作的内容儲存為一個檔案.
--我個人還有一個小技巧,儲存的檔案可以使用vim打開這樣檢視非常友善,如果在emacs再次儲存,在vim裡面再次加載就ok了.
8.優點和缺點:
--缺點
--不能在裡面使用edit指令,會出現亂碼,調用emacs也沒用.linux下。windows下沒有這種問題。
--實際上沒有rlwrap+sqlplus友善。
--優點
--可以使用編輯器上下左右移動。檢視顯示結果。輸出的指令也可以回車執行。例子:
SCOTT@test01p> select 'select * from emp;' from dual ;
'SELECT*FROMEMP'
-----------------
select * from emp;
SCOTT@test01p> select * from emp;
....
9.感覺emacs太複雜了.我的.emacs設定:(儲存在C:\Users\Administrator\AppData\Roaming目錄下)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes (quote (manoj-dark)))
'(inhibit-startup-screen t))
(custom-set-faces
;; custom-set-faces was added by Custom.
'(default ((t (:family #("新宋體" 0 3 (charset chinese-gbk)) :foundry "outline" :slant normal :weight normal :height 115 :width normal)))))
;; add by lfree ,no wrap.
;; for vertically-split windows
(setq truncate-partial-width-windows nil)
;; set windows size
(setq default-frame-alist
'((height . 60) (width . 220) (menu-bar-lines . 20) (tool-bar-lines . 0)))