[20141024]使用emacs連線使用oracle資料庫

lfree發表於2014-10-24

[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.
;; 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.
'(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-default truncate-lines t)
(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)))

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

相關文章