1 如何啟用sqlplus的autotrace功能?【pl/sql dev不支援這個功能】
要用sys使用者登入並下列步驟:
(1)@?\rdbms\admin\utlxplan --建立plan_table表
(2)10G之前plan_table是沒有同義字的,所以要加上create public synonym plan_table for plan_table。【此步:option】因為:In 10g, you don't need to create plan_table in your schema to explain plan. It uses the table plan_table$ belonging to SYS through a public synonym. The table is a session duration-based global temporary table. Makes perfect sense!
(3)grant all on plan_table to public
(4)@?\sqlplus\admin\plustrce
到此為止,DBA使用者首先被授予了plustrace角色,然後我們可以把plustrace授予public。如果你需要限制Autotrace許可權,可以把對public的授權改為對特定user的授權。例如:grant plustrace to scott。
【倘若根據以上步驟不行,則:
1.
1.)什麼使用者執行的set autotrace
2.)plan_table和plustrace是否按照要求建立和授權
2.
如果都已經按照要求做過,還報錯的話,可以grant select any dictionary to your_user,再驗證一下是否可以使用。
3.
再不行drop plan_table重建呢?
】
Notice:
(1)Explain 唯一的限制是使用者必須是所解釋事物的所有者,否則可能報錯。
(2)在pl/sql dev中,我們可以使用explain plan for+ select字句,然後再執行select * from table(DBMS_XPLAN.display)。
關於Autotrace幾個常用選項的說明:
Set autotrace off :預設值。
Set autotrace on :含查詢輸出,執行計畫,統計資訊
On後有兩個選擇性參數:
Explain:含查詢輸出,執行計畫
Statistics:含查詢輸出,統計資訊
Set autotrace traceonly:含執行計畫,統計資訊