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>
可以看到登錄之後 SQLPLUS按照login.sql文件進行相應設置