sqlplus在启动时会自动运行两个脚本:glogin.sql、login.sql这两个文件
执行顺序为
1.默认在在$ORACLE_HOME/sqlplus/admin路径下查找glogin.sql文件执行
2.默认在在当前路径下查找login.sql文件执行,若未查找到对应文件则执行3
3.判断是否设置SQLPATH环境变量,如果设置了该变量则在对应路径下查找并执行,未找到则停止查找
可以在login.sql文件中加入一些常用设置使用SQLPLUS时更便捷,以下试验在ORACLE 11.2.0.1.0上进行
默认$ORACLE_HOME/sqlplus/admin路径下存在glogin.sql文件
当前用户的profile文件中设置SQLPATH环境变量 export SQLPATH=$ORACLE_HOME/sqlplus/admin:$SQLPATH
在默认路径下加入我们自己的login.sql文件,以下配置为常用配置
--SQLPLUS默认编辑器设置为vi
define _editor=vi
--默认打开DBMA_OUTPUT,这样不必要每次在输入这个命令,同时将默认缓冲池设置得尽可能大
set serveroutput on size 1000000
--假脱机输出文本时,会去除文本行两端的空格,而且行宽不定,如果设置为off(默认设置),假脱机输出的文本行宽度则等于所设置的linesize
set trimspool on
--设置选择LONG和CLOB列时显示的默认字节数
set long 5000
--设置显示的文本宽为200个字符
set linesize 200
--设置SQLPLUS多久打印一次标题,将此参数设置大些这样每页只显示一次标题
set pagesize 9999
--设置AUTOTRACE得到解释计划输出的默认宽度,一般80足够放下整个计划
column plan_plus_exp format a80
--设置SQLPLUS提示符,显示格式为用户@数据库名
column global_name new_value gname
set termout off
define gname=idle
column global_name new_value gname
select lower(user) ||'@'|| substr(global_name,1,decode(dot,0,length(global_name),dot-1)) global_name
from (select global_name,instr(global_name,'.') dot from global_name);
set sqlprompt '&gname>'
set termout on
使用scott用户登录后如下
[oracle@RHEL65 ~]$ sqlplus scott/oracle
SQL*Plus: Release 11.2.0.1.0 Production on Sat Jan 23 00:11:26 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
scott@ORCL>select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
7566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
7782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10
7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
7839 KING PRESIDENT 1981-11-17 00:00:00 5000 10
7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
7900 JAMES CLERK 7698 1981-12-03 00:00:00 950 30
7902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
7934 MILLER CLERK 7782 1982-01-23 00:00:00 1300 10
14 rows selected.
scott@ORCL>set autot trace exp stat;
scott@ORCL>select * from emp;
14 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 532 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 532 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
1630 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
14 rows processed
scott@ORCL>