how to generate explain plan for entire stored procedure

守給你的承諾、 提交于 2019-12-05 07:59:29

What you are generating is correctly called an "execution plan". "Explain plan" is a command used to generate and view an execution plan, much as AUTOTRACE TRACEONLY does in your example.

By definition, an execution plan is for a single SQL statement. A PL/SQL block does not have an execution plan. If it contains one or more SQL statements, then each of those will have an execution plan.

One option is to manually extract the SQL statements from the PL/SQL code and use the process you've already shown.

Another option is to active SQL tracing then run the procedure. This will produce a trace file on the server that contains the execution plans for all statements executed in the session. The trace is in fairly raw form so it is generally easiest to format it using Oracle's TKPROF tool; there are also various third-party tools that process these trace files as well.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!