在Oracle 10g之前,使用autotrace还需要创建plustrace角色,并把该角色授予所有用户:
@?\rdbms\admin\plustrace.sql
grant plustrace to public;
Oracle 10g之后autotrace的功能增强了,并简化了以上操作,一个autotrace就可以完成所有的输出。
使用autotrace命令格式如下:
set autot[race] {off|on|trace[only]} [exp[lain]] [stat[istics]]
追踪所有信息:
set autot on
只显示执行计划和统计信息而不查看执行结果:
set autot trace exp stat
在既要显示执行计划又要显示统计信息时,也可以简略写为
set autot trace
此时执行一个SQL观察输出结果
select count(*) from scott.emp;
已用时间: 00: 00: 00.03
执行计划
----------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FULL SCAN| PK_EMP | 14 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------
统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
1 consistent gets
1 physical reads
0 redo size
527 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
与explain工具的区别是:explain仅分析语句,而autotrace无论怎样,语句总是要被执行的。
停止追踪时
set autot off
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28974745/viewspace-2150342/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28974745/viewspace-2150342/