sqlplus中显示sql执行计划和统计信息

31 ,32 , 33 ,34  keywords : oracle  storage  structure

最详细讲解:

               1: doc 1   logical  storage structure

               2: doc 2  physical  storage  structure


打开oracle sqlplus  trace 的方法

打开后可以看到执行过程中的统计信息:

首先用dba登录:

 

drop role plustrace;
Role dropped.
create role plustrace;
Role created.
.
grant plustrace to dba with admin option;
Grant succeeded.


然后授权给HR;

 

 

GRANT PLUSTRACE TO HR; 
Grant succeeded.

然后用HR用户登录:

 

 

SQL> conn HR/HR
已连接。
SQL> set auto trace
SP2-0158: 未知的 SET autocommit 选项 "trace"
用法: SET AUTO[COMMIT] { OFF | ON | IMM[EDIATE] | n }
SQL> set autot trace
SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色
SP2-0611: 启用 STATISTICS 报告时出错


报了以上错误: 以上错误解决方法:  

 

1: 用oracle  dba用户登录

2:执行如下授权命令:

 

SQL> conn /as sysdba
已连接。
SQL> grant select on v_$sesstat to plustrace;

授权成功。

SQL>  grant select on v_$statname to plustrace;

授权成功。

SQL>  grant select on v_$mystat to plustrace;

授权成功。

SQL>  grant plustrace to dba with admin option;

授权成功。

SQL> grant plustrace to HR;

授权成功。

SQL> exit


授权完成后用oracle 普通用户HR登录: 打开  autotrace on 即可: 就能看到执行计划和 统计信息了。

 

 

SQL> conn HR/HR
已连接。
SQL> select count(*) from employees;

  COUNT(*)
----------
       107

SQL> set autotrace on
SQL> select count(*) from employees;

  COUNT(*)
----------
       107


执行计划
----------------------------------------------------------
Plan hash value: 3580537945

-------------------------------------------------------------------------
| Id  | Operation        | Name         | Rows  | Cost (%CPU)| Time     |
-------------------------------------------------------------------------
|   0 | SELECT STATEMENT |              |     1 |     1   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE  |              |     1 |            |          |
|   2 |   INDEX FULL SCAN| EMP_EMAIL_UK |   107 |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------


统计信息
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          1  consistent gets
          0  physical reads
          0  redo size
        420  bytes sent via SQL*Net to client
        416  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed


 







 

posted @ 2013-06-27 19:38  坚固66  阅读(408)  评论(0编辑  收藏  举报