zoukankan      html  css  js  c++  java
  • [转载]【原创】set autotrace on 报

    一、问题描述:

        今天想看一下SQL的执行计划,在PL/SQL的command窗口中输入set autotrace on时,报Cannot SET AUTOTRACE的错误。

    二、解决办法:

        这个命令必须在sql*plus中运行,在PL/SQL中会报错

    Microsoft Windows [版本 6.1.7601]
    版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

    C:UsersAdministrator>sqlplus scott/tiger

    SQL*Plus: Release 11.2.0.3.0 Production on 星期三 11月 20 11:16:52 2013

    Copyright (c) 1982, 2011, Oracle.  All rights reserved.


    连接到:
    Personal Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options

    SQL> set autotrace on;
    SQL> select * from emp;

    三、分析:

    在网搜解决方法时,发现即使在sql*plus中也有可能出现这个问题,虽然没有遇到,但是将这种情况下的解决方法先记下来备用:

    1.首先必须采用用Oracle的sqlplus登陆sys账号

    sqlplus " sys/sys@XXX as sysdba "

    2.然后执行如下脚本:

    (1)plustrce.sql (创建plustrace角色并授权)   脚本内容如下:

    -------------------

    set echo on

    drop role plustrace;
    create role plustrace;

    grant select on v_$sesstat to plustrace;
    grant select on v_$statname to plustrace;
    grant select on v_$mystat to plustrace;
    grant plustrace to dba with admin option;

    set echo off

    -------------------

    (2)utlxplan.sql (创建执行计划的表)脚本内容如下:

    --------------------

    create table PLAN_TABLE (
            statement_id       varchar2(30),
            plan_id            number,
            timestamp          date,
            remarks            varchar2(4000),
            operation          varchar2(30),
            options            varchar2(255),
            object_node        varchar2(128),
            object_owner       varchar2(30),
            object_name        varchar2(30),
            object_alias       varchar2(65),
            object_instance    numeric,
            object_type        varchar2(30),
            optimizer          varchar2(255),
            search_columns     number,
            id                 numeric,
            parent_id          numeric,
            depth              numeric,
            position           numeric,
            cost               numeric,
            cardinality        numeric,
            bytes              numeric,
            other_tag          varchar2(255),
            partition_start    varchar2(255),
            partition_stop     varchar2(255),
            partition_id       numeric,
            other              long,
            distribution       varchar2(30),
            cpu_cost           numeric,
            io_cost            numeric,
            temp_space         numeric,
            access_predicates  varchar2(4000),
            filter_predicates  varchar2(4000),
            projection         varchar2(4000),
            time               numeric,
            qblock_name        varchar2(30),
            other_xml          clob
    );

    --------------------

    3.然后将该角色和对表的操作权限赋给用户

     grant all on plan_table to scott; 

     grant plustrace to scott; 

  • 相关阅读:
    更换惠普G32笔记本的风扇和硬盘,内存条, 谨记 要做好CPU和显卡的 导热硅脂工作!
    怎么更新 WIN10里的SMBv1协议
    ubuntu-12.04.5-desktop-amd64 安装vmwaretools
    如何解决“ VMware Workstation 不可恢复错误: (vcpu-0) vcpu-0:VERIFY vmcore/vmm/main/cpuid.c:386 bugNr=1036521”
    联想移动硬盘无法访问 解决方法1
    阮一峰 ---开发者手册
    Earth Wind 一个查看全球风向的网站
    Linux帮助用法
    Linux历史命令管理以及用法
    Linux操作练习
  • 原文地址:https://www.cnblogs.com/liuzhuqing/p/7480294.html
Copyright © 2011-2022 走看看