ThomasKyte的login.sql设置如下
- define _editor=vim --设置sqlplus 默认编辑器
- set serveroutput on size 1000000 --打开dbms-out 设置缓冲区尽量大
- set trimspool on --设置脱机输出文本时,取出文本行两端的空格而且行宽不定
- set long 5000 --设置选择LONG和colb列时默认字节数
- set linesize 150 --设置sqlplus默认显示文本行宽为150字符
- set pagesize 9999 --设置sqlplus多久打印一次标题,尽量大,以便每页答应一个标题
- column plan_plus_exp format a80 --设置由autotrace得到的解释计划输出宽度.a80可以显示整个计划
- 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
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 );
column global_name new_value gname 告诉sqlplus取得一个新的global_name列的最后一个值,并且将值赋给gname,然后选出global_name,并且与登录名相连接
这样得到的sqlplus提示符如下
- [oracle@stark ~]$ sqlplus scott/***
- SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jul 12 23:27:06 2012
- Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
- Connected to:
- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- scott@STARK>
autotrace是sqlplus的一个工具可以现实执行计划(explain plan)以及所用的资源,对于以后的工作有很大的作用,autotrace的配置方式不止一种.一下是比较流行的一种.
以sys登录数据库,执行$ORACLE_HOME/rdbms/admin下面的utlxplan
- sys@STARK>@/oracle/10.2/rdbms/admin/utlxplan.sql ;
- Table created.
之后授权执行以下语句
- sys@STARK>grant all on PLAN_TABLE to sys;
- Grant succeeded.
如果想要所有用户都可以使用autotrace只需要将username更改为public就可以
以后只要执行sqldml语句(select,delete,update,megre,inster)就会生成报告.
他对于监视和调优这些语句很有帮助.
控制报告
set autotrace off --不生成报告,默认
set autotrace on --生成执行报告,包括执行路径和统计信息,同时返回执行结果
set autotrace on explain --只显示执行路径
set autotrace on statistics --只显示统计信息
set autotrace traceonly --与set autotrace on的区别是不显示执行结果
eg
- sys@STARK>set autotrace off;
- sys@STARK>select count(*) from tab;
- COUNT(*)
- ----------
- 3670
- sys@STARK>set autotrace on;
- sys@STARK>select count(*) from tab;
- COUNT(*)
- ----------
- 3670
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 3662916347
- ---------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- ---------------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 77 | 119 (1)| 00:00:02 |
- | 1 | SORT AGGREGATE | | 1 | 77 | | |
- | 2 | NESTED LOOPS OUTER | | 997 | 76769 | 119 (1)| 00:00:02 |
- |* 3 | TABLE ACCESS FULL | OBJ$ | 997 | 72781 | 32 (4)| 00:00:01 |
- | 4 | TABLE ACCESS CLUSTER| TAB$ | 1 | 4 | 1 (0)| 00:00:01 |
- |* 5 | INDEX UNIQUE SCAN | I_OBJ# | 1 | | 0 (0)| 00:00:01 |
- ---------------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 3 - filter("O"."TYPE#"<=5 AND "O"."OWNER#"=USERENV('SCHEMAID') AND
- "O"."TYPE#">=2 AND "O"."LINKNAME" IS NULL)
- 5 - access("O"."OBJ#"="T"."OBJ#"(+))
- Statistics
- ----------------------------------------------------------
- 0 recursive calls
- 0 db block gets
- 8382 consistent gets
- 0 physical reads
- 0 redo size
- 516 bytes sent via SQL*Net to client
- 492 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- sys@STARK>select count(*) from tab;
- COUNT(*)
- ----------
- 3670
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 3662916347
- ---------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- ---------------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 77 | 119 (1)| 00:00:02 |
- | 1 | SORT AGGREGATE | | 1 | 77 | | |
- | 2 | NESTED LOOPS OUTER | | 997 | 76769 | 119 (1)| 00:00:02 |
- |* 3 | TABLE ACCESS FULL | OBJ$ | 997 | 72781 | 32 (4)| 00:00:01 |
- | 4 | TABLE ACCESS CLUSTER| TAB$ | 1 | 4 | 1 (0)| 00:00:01 |
- |* 5 | INDEX UNIQUE SCAN | I_OBJ# | 1 | | 0 (0)| 00:00:01 |
- ---------------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 3 - filter("O"."TYPE#"<=5 AND "O"."OWNER#"=USERENV('SCHEMAID') AND
- "O"."TYPE#">=2 AND "O"."LINKNAME" IS NULL)
- 5 - access("O"."OBJ#"="T"."OBJ#"(+))
- sys@STARK>select count(*) from tab;
- COUNT(*)
- ----------
- 3670
- Statistics
- ----------------------------------------------------------
- 0 recursive calls
- 0 db block gets
- 8382 consistent gets
- 0 physical reads
- 0 redo size
- 516 bytes sent via SQL*Net to client
- 492 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- sys@STARK>set autotrace traceonly
- sys@STARK>select count(*) from tab;
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 3662916347
- ---------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- ---------------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 1 | 77 | 119 (1)| 00:00:02 |
- | 1 | SORT AGGREGATE | | 1 | 77 | | |
- | 2 | NESTED LOOPS OUTER | | 997 | 76769 | 119 (1)| 00:00:02 |
- |* 3 | TABLE ACCESS FULL | OBJ$ | 997 | 72781 | 32 (4)| 00:00:01 |
- | 4 | TABLE ACCESS CLUSTER| TAB$ | 1 | 4 | 1 (0)| 00:00:01 |
- |* 5 | INDEX UNIQUE SCAN | I_OBJ# | 1 | | 0 (0)| 00:00:01 |
- ---------------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 3 - filter("O"."TYPE#"<=5 AND "O"."OWNER#"=USERENV('SCHEMAID') AND
- "O"."TYPE#">=2 AND "O"."LINKNAME" IS NULL)
- 5 - access("O"."OBJ#"="T"."OBJ#"(+))
- Statistics
- ----------------------------------------------------------
- 0 recursive calls
- 0 db block gets
- 8382 consistent gets
- 0 physical reads
- 0 redo size
- 516 bytes sent via SQL*Net to client
- 492 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
设定退格
设定环境变量:
1)在bash下,把 stty erase ^H 添加到.bash_profile中
2)在csh下,把 stty erase ^H 添加到.cshrc中
下面是我今天的实现方法(在bash下)
[root@testdb ~]# su - oracle 进入oracle主目录,里面有 .bash_profile
[root@testdb ~]# vi .bash_profile 添加一行
stty erase ^H
:wq 保存退出
重新用oracle登录则可。
本文出自 “望月飞鱼” 博客,转载请与作者联系!