Oracle Sqlplus operating environment login.sql settings

When running Sqlplus, it is often necessary to set up the operating environment. It will be troublesome to adjust parameters every time you enter. Therefore, you can use the two files glogin.sql and login.sql provided by Oracle to initialize the environment of Sqlplus.

Each time Sqlplus is started, two scripts will be automatically executed: the two files glogin.sql and login.sql.

The execution order of SQLplus for these two files is:  

1.默认在在$ORACLE_HOME/sqlplus/admin路径下查找glogin.sql文件执行;

2.默认在当前路径下查找login.sql文件执行,若未查找到对应文件则执行3;

3.判断是否设置SQLPATH环境变量,如果设置了该变量则在对应路径下查找并执行,未找到则停止查找。

The following configuration example is performed under Oracle 11g:

Check whether the glogin.sql file exists in the $ORACLE_HOME/sqlplus/admin path

 You can set an environment variable SQLPATH so that it can be used in any directory.

Set the SQLPATH environment variable in the current user's profile file

export SQLPATH=$ORACLE_HOME/sqlplus/admin:$SQLPATH

Add our own login.sql file under the default path. The following configuration is the recommended common configuration.

--设置SQLPLUS默认编辑器为vi
define _editor=vi
--默认打开DBMA_OUTPUT,这样不必每次都输入这个命令,同时将默认缓冲池设置得尽可能大
set serveroutput on size 1000000
--假脱机输出文本时,会去除文本行两端的空格,而且行宽不定,如果设置为off(默认设置),假脱机输出的文本行宽度则等于所设置的linesize
set trimspool on
--设置选择LONG和CLOB列时显示的默认字节数
set long 5000
--设置显示的文本宽为300个字符
set linesize 300
--设置SQLPLUS多久打印一次标题,将此参数设置大些这样每页只显示一次标题
set pagesize 9999
--设置AUTOTRACE得到解释计划输出的默认宽度,一般80足够放下整个计划
column plan_plus_exp format a80
--设置SQLPLUS提示符,显示格式为用户@数据库名
set sqlprompt '&_user.@&_connect_identifier.> '

It is recommended that when operating a production database, it is best to configure the SQLplus prompt display format to prevent operation errors.

The effect after the configuration is completed is as follows:

You can see that after logging in to the database, SQLplus has set the corresponding display format according to the login.sql file.

Guess you like

Origin blog.csdn.net/GYN_enyaer/article/details/123568946