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
    








  • 相关阅读:
    django静态资源转移
    QT5 内置Multimedia开发音乐播放器
    Qt Creator 设置编码格式为 UTF-8
    QT 出错 moc_mainwindow.obj:-1: error: LNK2019: 无法解析的外部符号 " 中被引用...
    linux 安装node, 添加软链接,更改npm安装源
    django.template.exceptions.TemplateDoesNotExist: index.html
    centos下使用virtualenv建立python虚拟环境
    win7上 nginx 出现 403 Forbidden
    django安装xadmin中出现的报错汇总
    centos安装mysql57
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3159652.html
Copyright © 2011-2022 走看看