当前位置:数据库 > SQLServer >>

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

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登录:
[sql] 
drop role plustrace;  
Role dropped.  
create role plustrace;  
Role created.  
.  
grant plustrace to dba with admin option;  
Grant succeeded.  
 
然后授权给HR;
[sql] 
GRANT PLUSTRACE TO HR;   
Grant succeeded.  
然后用HR用户登录:
 
[sql] 
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] 
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] 
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  
 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,