【顯示執行計劃】在普通使用者下使用set autot 檢視執行計劃

楊奇龍發表於2010-09-09

在普通使用者下檢視執行計劃 時 ,會遇到如下問題:

SQL> CONN SCOTT/SCOTT
已連線。
SQL> SET AUTOT TRACE
蒐集統計資訊時出錯 ORA-942
SP2-0611: 啟用 STATISTICS 報告時出錯

SQL> SET AUTOT ON
蒐集統計資訊時出錯 ORA-942
SP2-0611: 啟用 STATISTICS 報告時出錯
SQL> SET AUTOT OFF
SQL> SET AUTOT ON
蒐集統計資訊時出錯 ORA-942
SP2-0611: 啟用 STATISTICS 報告時出錯

一般導致AUTOTRACE失敗不是因為PLAN_TABLE不存在,就是由於缺少PLUSTRACE角色或PLUSTRACE角色包含的檢視許可權。

SQL> grant plustrace to scott;
grant plustrace to scott
      *
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist  可見plustrace 角色不存在。

SQL> create role plustrace ;
Role created.
SQL> grant select on v_$sesstat to plustrace;
Grant succeeded.
SQL> grant select on v_$statname to plustrace;
Grant succeeded.
SQL> grant select on v$mystat to plustrace;
grant select on v$mystat to plustrace
                *
ERROR at line 1:
ORA-02030: can only select from fixed tables/views --容易犯的錯誤。

SQL> grant select on v_$mystat to plustrace;
Grant succeeded.
SQL> grant plustrace to scott;
Grant succeeded.
SQL> conn scott/scott
Connected.
SQL> set autot on
SQL> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON


Execution Plan
----------------------------------------------------------
Plan hash value: 1554282393
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     4 |    80 |     3   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| DEPT |     4 |    80 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------
Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          8  consistent gets
          5  physical reads
          0  redo size
        776  bytes sent via SQL*Net to client
        492  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          4  rows processed

SQL>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-673050/,如需轉載,請註明出處,否則將追究法律責任。

相關文章