Sqlplus查看执行计划

SQLPLUS查看执行计划

1、在sys用户下,创建角色plustrace
SQL> conn sys as sysdba
Enter password:
Connected.
SQL> @$ORACLE_HOME/sqlplus/admin/plustrce.sql

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

2、在sys用户下,把PLUSTRACE角色赋予一般用户DBKMS00
SQL> grant PLUSTRACE to DBKMS00;
Grant succeeded.

3、在DBKMS00用户下,查看执行计划
SQL> conn DBKMS00/DBKMS00
Connected.
SQL> show linesize
linesize 80
SQL> set linesize 200
SQL>
SQL> set autotrace traceonly
SQL> select * from t_gy_pos_pmk where gy_pos_no='1';
SQL>
SQL>


如果无法设置set autotrace on,可以使用另一种方法查看执行计划
SQL> set autotrace traceonly
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report
SQL>
SQL> explain plan for select * from t_gy_pos_pmk where gy_pos_no='1';
SQL> select * from table(dbms_xplan.display());
SQL>

猜你喜欢

转载自mandy-rxr.iteye.com/blog/2250338