2010-12-22 64 views
6

我通常會產生使用說明計劃下在sqlplus:如何生成解釋計劃整個存儲過程

SET AUTOTRACE ON 
SET TIMING ON 
SET TRIMSPOOL ON 
SET LINES 200 
SPOOL filename.txt 
SET AUTOTRACE TRACEONLY; 

{query goes here} 

SPOOL OFF 
SET AUTOTRACE OFF 

但是如果我要生成一個存儲過程的解釋計劃?

有沒有辦法爲整個存儲過程生成解釋計劃? SP沒有輸入/輸出參數。

回答

6

正在生成的內容正確地稱爲「執行計劃」。 「解釋計劃」是一個用於生成和查看執行計劃的命令,就像AUTOTRACE TRACEONLY在您的示例中所做的一樣。

根據定義,執行計劃適用於單個SQL語句。 PL/SQL塊沒有執行計劃。如果它包含一個或多個SQL語句,那麼每個語句都會有一個執行計劃。

一種方法是從PL/SQL代碼中手動提取SQL語句,並使用您已經顯示的過程。

另一種選擇是激活SQL跟蹤,然後運行該過程。這將在服務器上生成一個跟蹤文件,其中包含會話中執行的所有語句的執行計劃。跟蹤相當原始,因此使用Oracle的TKPROF工具進行格式化通常最容易;還有各種處理這些跟蹤文件的第三方工具。

+0

好的。我會去手動提取的方式。但是,現在如果我在存儲過程中有一些循環塊會怎麼樣。我將如何運行這些循環塊的執行計劃,因爲它們具有BEGIN和END – 2010-12-22 16:49:28

1
Hi I have done like below for the stored procedure: 
SET AUTOTRACE ON 
SET TIMING ON 
SET TRIMSPOOL ON 
SET LINES 200 
SPOOL filename.txt 
SET AUTOTRACE TRACEONLY; 
@your stored procedure path 
SPOOL OFF 
SET AUTOTRACE OFF 

And got the below statistics: 

    Statistics 
----------------------------------------------------------- 
       6 CPU used by this session 
       8 CPU used when call started 
       53 DB time 
       6 Requests to/from client 
      188416 cell physical IO interconnect bytes 
      237 consistent gets 
      112 consistent gets - examination 
      237 consistent gets from cache 
      110 consistent gets from cache (fastpath) 
      2043 db block gets 
       1 db block gets direct 
      2042 db block gets from cache 
      567 db block gets from cache (fastpath) 
       27 enqueue releases 
       27 enqueue requests 
       4 messages sent 
       31 non-idle wait count 
       19 non-idle wait time 
       44 opened cursors cumulative 
       2 opened cursors current 
       22 physical read total IO requests 
      180224 physical read total bytes 
       1 physical write total IO requests 
      8192 physical write total bytes 
       1 pinned cursors current 
      461 recursive calls 
       4 recursive cpu usage 
      2280 session logical reads 
     1572864 session pga memory 
       19 user I/O wait time 
       9 user calls 
       1 user commits 
No Errors. 
Autotrace Disabled