sqlplus裡如何修改default的系統編輯器

warehouse發表於2010-03-08

簡單的整理了一下win和linux下的辦法,和doc的描述稍有出入

[@more@]

doc原文如下:

Using a System Editor from SQL*Plus

If you run an ED or EDIT command at the SQL*Plus prompt, then the system starts an operating system editor, such as ed, emacs, ned, or vi. However, the PATH environment variable must include the directory where the editor executable is located.

When you start the editor, the current SQL buffer is placed in the editor. When you exit the editor, the changed SQL buffer is returned to SQL*Plus.

You can specify which editor should start by defining the SQL*Plus _EDITOR variable. You can define this variable in the glogin.sql site profile or the login.sql user profile. Alternatively, you can define it during the SQL*Plus session. For example, to set the default editor to vi, run the following command:

SQL> DEFINE _EDITOR=vi

If you do not set the _EDITOR variable, then the value of either the EDITOR or the VISUAL environment variable is used. If both environment variables are set, then the value of the EDITOR variable is used. If _EDITOR, EDITOR, and VISUAL are not specified, then the default editor is ed.

When you start the editor, SQL*Plus uses the afiedt.buf temporary file to pass text to the editor. You can use the SET EDITFILE command to specify a different file name. For example:

SQL> SET EDITFILE /tmp/myfile.sql

SQL*Plus does not delete the temporary file.

測試和doc描述稍微有點出入

我測試的win和linux下結果都一樣:

SQL> define
DEFINE _DATE = "08-3月 -10" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "orcl" (CHAR)
DEFINE _USER = "SYS" (CHAR)
DEFINE _PRIVILEGE = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1002000100" (CHAR)
DEFINE _EDITOR = "Notepad" (CHAR)
DEFINE _O_VERSION = "Oracle Database 10g Enterprise Edition Release 10.2.0.
1.0 - Production
With the Partitioning, OLAP and Data Mining options" (CHAR)
DEFINE _O_RELEASE = "1002000100" (CHAR)
SQL>

進入sqlplus之後透過執行define命令發現_EDITOR的值就是default的呼叫os的編輯器,可以在sqlplus中直接修改自己想用的編輯器:

SQL> define _editor="C:Program FilesEditPlus 2editplus.exe"
SQL> define
DEFINE _DATE = "08-3月 -10" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "orcl" (CHAR)
DEFINE _USER = "SYS" (CHAR)
DEFINE _PRIVILEGE = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1002000100" (CHAR)
DEFINE _EDITOR = "C:Program FilesEditPlus 2editplus.exe" (CHAR)
DEFINE _O_VERSION = "Oracle Database 10g Enterprise Edition Release 10.2.0.
1.0 - Production
With the Partitioning, OLAP and Data Mining options" (CHAR)
DEFINE _O_RELEASE = "1002000100" (CHAR)
SQL>

修改的時候最好寫上被呼叫的編輯器的絕對路徑,否則可能和環境變數有關。

透過在sqlplus中直接修改_EDITOR的值作用範圍是該session,如果要想永久生效,需要把define_editor="C:Program FilesEditPlus 2editplus.exe"加到$ORACLE_HOME/sqlplus/admin/glogin.sql檔案裡,linux下也一樣,linux如果環境變數設定好了,那麼可以直接新增define_editor=vi到glogin.sql檔案裡,主要是define_editor而不是doc上所提到的_editor...

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

相關文章