1、 先在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
2、产生plustrace角色,然后在sys用户下把此角色赋予一般用户&username
SQL> grant plustrace to &username;
3、 SQL>@/ORACLE_HOME/rdbms/admin/utlxplan.sql,它创建一个plan_table,用来存储分析SQL语句的结果。
4、 在SQL/PLUS的窗口运行以下命令(可以用普通用户)
set time on; (说明:打开时间显示)
set autotrace on; (说明:打开自动分析统计,并显示SQL语句的运行结果)
set autotrace traceonly; (说明:打开自动分析统计,不显示SQL语句的运行结果)
5、 接下来你就运行测试SQL语句,看到其分析统计结果了。一般来讲,我们的SQL语句应该避免对大表的全表扫描。 (可以使用普通用户)
6、关闭以上功能,在SQL/PLUS的窗口运行以下命令
set time off; (说明:关闭时间显示)
set autotrace off; (说明:关闭自动分析统计)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26674381/viewspace-716069/
,如需转载,请注明出处,否则将追究法律责任。