【原创】set autotrace …
2014-03-10 10:10
190 查看
一、问题描述:
今天想看一下SQL的执行计划,在PL/SQL的command窗口中输入set autotrace on时,报Cannot SET
AUTOTRACE的错误。
二、解决办法:
这个命令必须在sql*plus中运行,在PL/SQL中会报错:
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>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;
今天想看一下SQL的执行计划,在PL/SQL的command窗口中输入set autotrace on时,报Cannot SET
AUTOTRACE的错误。
二、解决办法:
这个命令必须在sql*plus中运行,在PL/SQL中会报错:
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>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;
相关文章推荐
- set autotrace 理解
- oracle,Cannot SET AUTOTRACE解决问题 (只能在sql plus下执行)
- set Autotrace使用的问题与解决
- set autotrace参数详解
- ORACLE set autotrace
- 在sqlplus中set autotrace on 出错的解决办法:SP2-0613,SP2-0611
- oracle,Cannot SET AUTOTRACE解决问题
- Oracle 使用scott用户 set autotrace on报错 SP2-0618,SP2-0611
- Oracle10g SQL优化辅助工具之 set autotrace
- set autotrace的用法和含意及区别
- 普通用户使用set autotrace
- set Autotrace的使用
- Oracle set autotrace 时提示:Cannot find the Session Identifier. Check PLUSTRACE role is enabled
- ORACLE set autotrace in SQL*Plus
- 实用set autotrace xxx 来获取执行计划
- oracle,Cannot SET AUTOTRACE解决问题
- [Sql*Plus] Set up Explain Plan and Autotrace
- set autotrace 报错sp2-0613&sp2-0618
- set autotrace 到底有没有执行SQL?