cannot SET AUTOTRACE问题解决

SET AUTOTRACE参数

SET AUTOTRACE OFF ---------------- 不生成AUTOTRACE 报告,这是缺省模式
SET AUTOTRACE ON EXPLAIN ------ AUTOTRACE只显示优化器执行路径报告
SET AUTOTRACE ON STATISTICS -- 只显示执行统计信息
SET AUTOTRACE ON ----------------- 包含执行计划和统计信息
SET AUTOTRACE TRACEONLY ------ 同set autotrace on,但是不显示查询输出


一、问题描述:

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

二、解决办法:

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

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

C:\Users\Administrator>sqlplusscott/tiger

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

Copyright (c) 1982, 2011, Oracle.  All rightsreserved.


连接到:
Personal Oracle Database 11g Release 11.2.0.3.0 - 64bitProduction
With the Partitioning, OLAP, Data Mining and Real ApplicationTesting 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 toscott; 

 grant plustrace to scott; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值