怎样让普通用户也能在 sqlplus 里 set autotrace on

先在sys用户下运行@/ORACLE_HOME/sqlplus/admin/plustrce.sql

内容:
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_$session to plustrace;
grant plustrace to dba with admin option;
set echo off

产生plustrace角色,然后在sys用户下把此角色赋予一般用户

SQL> grant plustrace to &username;

    然后找到/ORACLE_HOME/rdbms/admin/utlxplan.sql,然后在当前用户SQL>下运行,它创建一个plan_table,用来存储分析SQL语句的结果。

create table PLAN_TABLE (
statement_id    varchar2(30),
timestamp       date,
remarks         varchar2(80),
operation       varchar2(30),
options         varchar2(30),
object_node     varchar2(128),
object_owner    varchar2(30),
object_name     varchar2(30),
object_instance numeric,
object_type     varchar2(30),
optimizer       varchar2(255),
search_columns  number,
id              numeric,
parent_id       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));

    在SQL/PLUS的窗口运行以下命令


set time on; (说明:打开时间显示)
set autotrace on; (说明:打开自动分析统计,并显示SQL语句的运行结果)
set autotrace traceonly; (说明:打开自动分析统计,不显示SQL语句的运行结果)

    接下来你就运行测试SQL语句,看到其分析统计结果了。一般来讲,我们的SQL语句应该避免对大表的全表扫描。

    关闭以上功能,在SQL/PLUS的窗口运行以下命令

set time off; (说明:关闭时间显示)
set autotrace off; (说明:关闭自动分析统计)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25380220/viewspace-706904/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25380220/viewspace-706904/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值