zoukankan      html  css  js  c++  java
  • 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
    








  • 相关阅读:
    从今天起,我要在博客园装13了,听说这里装的好可以得高薪
    HTML5 选择前置摄像头,选择后置摄像头
    canvas图片base64编码后,ajax提交到后台
    238. Product of Array Except Self
    230. Kth Smallest Element in a BST
    229. Majority Element II
    228. Summary Ranges
    227. Basic Calculator II
    223. Rectangle Area
    222. Count Complete Tree Nodes
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3159652.html
Copyright © 2011-2022 走看看