How to run Explain Plan for SP?

Can we run Explain Plan for SP??

EXPLAIN PLAN creates an execution plan for SQL statements. PL/SQL is not SQL.
PL/SQL procedures can contain SQL, yes. These SQLs can be copied and pasted from PL/SQL into something like TOAD and execution plan determined.
However, if the aim is to see the "execution/performance plan" for PL/SQL code, then you need to profile the PL/SQL code using the DBMS_PROFILER package. This will tell you the execution path and elapsed time to execute a line of PL/SQL.
Details can be found in the [url http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_profil.htm#sthref5502]Oracle® Database PL/SQL Packages and Types Reference guide.

Similar Messages

  • How to find Explain Plan for a large querry which has multiple sub querries

    Hi All,
    I have a Package which has many procedures and one of the procedure has a cursor which is like 2000 lines. This cursor has a main select statement which again has many select statements in it.
    Now how do I do the explain plan for the main select statement?
    If it can be done easier way in toad(or SQLPLUS), please tell me...

    When your query takes too long ...

  • Explain plan for running query

    Hi everyone,
    I come to know how to generate explain plan for a given query by giving
    Explain plan for select * fro emp;
    Consider a query running for 5 hrs in a session and i want to genrate explain plan for that current query in its 4th hour i dont know the sql as well
    all the steps by step would be much apppreciated
    like finding Current SQL then so on
    Thanks
    Shareef

    912856 wrote:
    Hi everyone,
    I come to know how to generate explain plan for a given query by giving
    Explain plan for select * fro emp;
    Consider a query running for 5 hrs in a session and i want to genrate explain plan for that current query in its 4th hour i dont know the sql as well
    all the steps by step would be much apppreciated
    like finding Current SQL then so on
    Thanks
    ShareefYOu can also use dbms_xplain to generate plan used in v$sql. like for example
    SQL>SELECT  SQL_ID,  CHILD_NUMBER FROM  V$SQL WHERE  SQL_TEXT LIKE 'select * from em%';
    SQL_ID        CHILD_NUMBER
    6kd5fkqdjb8fu            0
    SQL>SELECT  * FROM  TABLE(DBMS_XPLAN.DISPLAY_CURSOR('6kd5fkqdjb8fu',0,'ALLSTATS'));If you need the actual tuntime statistics used by sql statement then you need to put hint /*+ gather_plan_statistics */ in sql ststement, something like
    select /*+ gather_plan_statistics */ * from emp;
    and then generate the explain plan for this
    Have a look
    http://hoopercharles.wordpress.com/2010/03/01/dbms_xplan-format-parameters/
    select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));

  • Question about running explain plan

    I tried to run explain plan for a simple query, just to familiarize myself with how to do it. (I have another query that's taking a long time, and I've never run explain plan before). I got an error, googled it, and discovered I had to run the file at @%ORACLE_HOME%\rdbms\admin\utlxplan.sql first, to create the Plan_Table. Well, I tried to run that file and I get the error that I don't have priveleges on the tablespace. This really doesn't surprise me, as my access is read-only. Is there any way around this? I don't know a whole lot about databases, so forgive me if these following questions are dumb, but...
    1) is that file basically trying to create a table (called Plan_Table) within the schema I'm in (the only schema I have access to)?
    2) can my company's DBA run that file for me to create the Plan_Table?

    What version of the database are you on?
    You can get run-time execution plans from V$SQL_PLAN. You will need permission to read the V$ views. First find your query in V$SQL_PLAN (you can do a text search; putting a comment in like '--my_query' can help), then join to V$SQL_PLAN to find the query plan that that query used - join by the ADDRESS and HASH_VALUE columns.
    Otherwise, see if you can get insert/update/delete access on just that one table when your DBA creates it
    Good luck.

  • Running explain plan on a prepared statement

    I'm using IBatis to run queries against an Oracle database. IBatis runs the queries as prepared statements. I want to run explain plan on the prepared statements.
    I already have a shim -- a proxy java.sql.Connection object -- that takes the SQL used to create a prepared statement (e.g., "select a, b, c from table d where c = ?"), returns a proxy java.sql.PreparedStatement, and then on the PreparedStatement's execute(), interpolates the bound parameters into the SQL statement, and runs Explain Plan on that (e.g, preparedStatement.setInt(5) is called, followed by preparedStatement.execute(), which results in my proxy running "explain plan for select a, b, c from table d where c = 5;")
    Using Spring configuration, I can transparently insert the shim and get explain plans for all queries run through that Connection.
    The problem is this: I'm explaining the plan for the SQL with the bound parameters, not necessarily the SQL run for the prepared statement.
    Assume that in the above example, there exists an index on column c in table d, and that 5% of d's rows have the value 1, 15% have the value 2, and 80% have the value 3.
    For "select a, b, c from table d where c = 1", Oracle will use the index. But for "select a, b, c from table d where c = 3", Oracle will do a full table scan.
    What I want to know is what Oracle will do for "select a, b, c from table d where c = ?" when "?" is an unknown, arbitrary value subsequently bound to 1 or to 3.
    As I understand it, the query plan for a prepared statement is done once, when the prepared statement is created. At execute time (as I understand it), the query plan is not reformulated based on the actual bound values (though partition pruning is recalculated).
    So how can I find out what query plan is actually be used for prepred statement?
    Thanks.

    I already have a shim -- a proxy java.sql.Connection object -- that takes the SQL used to create a prepared statement I believe explain plan is part of PL/SQL rather than external to it.
    As such you can pass it via a prepared statement. It is just a matter of getting the syntax correct. And of course collecting the result.
    The syntax is going to be be something like the following. You would use it just like you use the existing sql.
    begin
       select ... from ... where c = ?;
    endThe result might be returned a result sets (plural). If so you would need to code appropriately for that.

  • Explain Plan for domain index

    I am running explain plan for queries using a domain index. i.e. an oracle text 'contains' clause. The usage of the domain index appears in the plan o.k, but I am interested in seeing the underlying access to the DR$...$I etc tables and assoicated indexes belonging to ctxsys. Is it possible to see this access ?
    Basically I have all the objects created by the domain index in their own tablespace using a storage preference, but I am wondering if the sub indexes should be moved out from the sub tables for better performance ? Any guidance is appreciated.

    I am running explain plan for queries using a domain index. i.e. an oracle text 'contains' clause. The usage of the domain index appears in the plan o.k, but I am interested in seeing the underlying access to the DR$...$I etc tables and assoicated indexes belonging to ctxsys. Is it possible to see this access ?
    Basically I have all the objects created by the domain index in their own tablespace using a storage preference, but I am wondering if the sub indexes should be moved out from the sub tables for better performance ? Any guidance is appreciated.

  • Explain plan for MVIEW....

    Hi All,
    please tell me how to invoke EXPLAIN PLAN for CREATE MATERIALIZED VIEW.
    while i am trying to get plan i am getting following error
    ORA-00900: invalid SQL statement
    Thanks in advance.

    Thanks for reply.
    I need it for estimation and solution design. so all
    parameters are necessary. second thing is DDL and
    simple SELECT statements plan are differ. I can get
    explain plan for CREATE TABLE AS SELECT but not for
    CREATE MV.
    Regards,
    Santosh.In case you didn't notice: Create table as select (CTAS) is also DDL.
    There is nothing additionally from point of the execution plan that is added by the CREATE MV command.

  • How to change the explain plan for currently running query?

    Hi All,
    I am using Oracle enterprise 9i edition. I have a query which frames dynamically and running in the database. I noticed a table with 31147758 rows
    in the query which has no indexes and taking more time to process. I tried to create an INdex on that table. I know the query is already running with a FULL table scan. Is it possible to change the explain plan for the current running query to consider the INDEX?
    [code]
    SELECT /*+ USE_HASH (c,e,b,a) */
    d.att_fcc extrt_prod_dim_id,
    d.att_fcc compr_prod_dim_id,
      a.glbl_uniq_id glbl_uniq_id,
      to_date(c.dit_code,'RRRRMMDD')STRT_DT,
      (to_date(c.dit_code,'RRRRMMDD')+150)END_DT,
      a.pat_nbr pat_id,
      a.rxer_id       rxer_id,
      e.rxer_geog_id  rxer_geog_id,
      a.pharmy_id pharmy_id,
      a.pscr_pack_id pscr_pack_id,
      a.dspnsd_pack_id dspnsd_pack_id,
      DENSE_RANK () OVER (PARTITION BY a.pat_nbr ORDER BY c.dit_code) daterank,
      COUNT( DISTINCT d.att_fcc ) OVER (PARTITION BY a.pat_nbr, c.dit_code) event_cnt
      DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
    d.att_fcc
      ORDER BY c.dit_code) prodrank,
      DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
    d.att_fcc
      ORDER BY c.dit_code DESC) stoprank
      FROM
      pd_dimitems c,
       pd_pack_attribs   d ,
        lrx_tmp_rxer_geog e,
        lrx_tmp_pat_daterank p,
        lrx_tmp_valid_fact_link     a
        WHERE c.dit_id = a.tm_id
        AND   e.rxer_id = a.rxer_id
        AND   a.glbl_uniq_id = p.glbl_uniq_id
        AND   p.daterank > 1
      AND   a.pscr_pack_id = d.att_dit_id
    [/code]
    The table lrx_tmp_pat_daterank is having that 31147758 rows. So I am wondering how to make the query to use the newly created index on the table?

    Why do you think using Indexes will improve the performance of the query? How many rows this query is returning? Optimizer might chose a Full table scan when it finds out that Index plan might not be useful. Why are you using /*+ USE_HASH (c,e,b,a) */ hint? This Hint will force oracle to use Full table scan instead of using the index. Try removing it and see if the plan changes.
    Regards,

  • How to enable Explain plan in TOAD

    Hi,
    I am using toad version 8.6.1.Whenever i login as my userid and run a sql stmnt i am trying to get explain plan from toad explain plan button.But it's not showing anything some times it says insuffcient privileges.I created synonym called plan_table which is based on actual plan_table.But no luck.Can you pls help me how to enable explain plan in toad
    Thanks
    Anand

    Anand,
    in earlier versions of Toad you could use the notoad.sql or toadprep.sql to create the required tables.
    In your version it is probably already has been replaced by menu option Tools->Server Side Object Wizard.
    Toad does not use the plan_table - it creates it's own set of tables including the table for the explain plan.
    Mike

  • Explain Plan for Procedure

    Hi,
    For getting the explain plan for a query, we use the statement
    "explain plan for " + Query
    Similarly, to get an explain plan for a procedure, do we have any way like
    "explain plan for " + "Execute " + Procedure
    How do we get an explain plan for a procedure that is executed
    Thanks in Advance.

    teckfreak wrote:
    Hi Robert,
    I am working on an utility application which will execute the procedure and show the explain plan to the user for him to analyze the explain plan and take necessary steps for optimization. I am showing the Procedure inputs to the user, allowing him to enter values and taking them and executing the procedure. I am setting the trace and extracting the explain plan for the procedure using TKPROF utility and showing it to the user.
    While doing so, the trace file is stored in udump folder. I am accessing the trace file from TKPROF utility. I am able to run the TKPROF from the command prompt. But if I try automating the TKPROF command in a .NET application using Process.Start, it says "Not able to access the file.". I tried giving full permissions to Everyone and it still throws the error. Kindly guide me how to proceed.. A different approach that you might want to consider (as indicated by William):
    - Flush the shared pool and use a unique MODULE description for each execution of your procedure (e.g. using DBMS_APPLICATION_INFO.SET_MODULE), e.g. using a logon trigger
    - Query V$SQL for your unique MODULE description and run DBMS_XPLAN.DISPLAY_CURSOR for each corresponding child cursor found (SQL_ID + CHILD_NUMBER) in the shared pool. This plan generation could be automated using a procedure
    The result of this approach corresponds to the tracing using TKPROF since it will provide the actual execution plans used at runtime rather than separate EXPLAIN PLAN results which might differ from the actual plans.
    This assumes that your shared pool is sufficiently large to hold all the child cursor created by your procedure without aging them out while the procedure is running. It's probably also only applicable to an environment where not too much work is being done while running this test and the recommended flushing of the shared pool.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • How to run production planning  in APO

    Hi gurus,
    how to run production planning  in APO.
    Can u explain me.
    prasad

    Prasad,
    An unfocused question; a similar answer.  Try online help for a start
    http://help.sap.com/saphelp_scm70/helpdata/en/2a/18dc37c7f2d67ae10000009b38f889/frameset.htm
    Best Regards,
    DB49

  • Explain plan for query with variables

    Trying to Explain plan for some sql in sql*plus. The query has a variable in it. How do I do this ?
    I did look into explain plan and dbms_xplan but could not find anything with variables

    use sqlplus bind variables:
    SQL> --define variable
    SQL> var x varchar2
    SQL> -- notice the colon prefixing the variable
    SQL> explain plan for select * from customer where cid = :x;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 1709312366
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    67 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| CUSTOMER |     1 |    67 |     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | CID      |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("CID"=:X)
    14 rows selected.the variable does not need to be set to explain the query, since explain does not actually execute.
    Edited by: shoblock on Nov 6, 2008 4:51 PM

  • Explain plan for Procedures

    Hi,
    I know we can generate explain plan for queries using "Explain plan" statement or "Autotrace option". I would like to know how can we generate explain plan for oracle procedures.
    Thanks in Advance..

    Check this link very helpful info from Rob
    When your query takes too long ...
    There are no explain plan for procedures.
    MAy be you want to do DBMS_PROFILER for procedures execution

  • Explain plan for Query performance

    Hi Gurus,
    I need to improve the performance of a procedure. The procedure has the below QUery. I dont have Idea on how to imrpove the perf by seeing the explain plan. Can anyone please help me to explain where I need to change the code.
    The below are the code and Explain plan for the same.
    -----------Code----------------------------
    SELECT IV_STORECODE AS STORECODE,
                                   TO_CHAR(RD.ITEMCODE) AS ITEMCODE,
                                   C.ITEMCATEGORYNAME,
                                   ISUB.ITEMSUBCATEGORY1NAME
                              FROM RECEIPTS R
                             INNER JOIN RECEIPTDETAILS RD
                                ON R.RECEIPTID = RD.RECEIPTID
                             INNER JOIN ITEMCOMPANY IC
                                ON IC.ITEMCODE = RD.ITEMCODE
                             INNER JOIN ITEMCATEGORY C
                                ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
                             LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
                                ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
                               AND ISUB.ITEMSUBCATEGORY1ID IN
                                   (SELECT ITEMSUBCATEGORY1ID
                                      FROM ITEMSUBCATEGORY1
                                     WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
                             INNER JOIN STORE SE
                                ON SE.STORECODE = R.STORECODE
                             WHERE R.STORECODE = IV_STORECODE
                               AND SE.HOSPITALID = IV_HOSPITALID
                               AND TRUNC(R.CREATEDDATE) BETWEEN V_FROMDATE AND
                                   V_TODATE
                               AND R.STATUSID NOT IN (99, 5)
                                  AND
                                   (IV_DRUGTYPE IS NULL OR
                                   IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
                            UNION
                            SELECT IV_STORECODE AS STORECODE,
                                   TO_CHAR(STD.ITEMCODE) AS ITEMCODE,
                                   C.ITEMCATEGORYNAME,
                                   ISUB.ITEMSUBCATEGORY1NAME
                              FROM STOCKTRANSACTION ST
                             INNER JOIN STOCKTRANSACTIONDETAILS STD
                                ON ST.STOCKTRANSACTIONID = STD.STOCKTRANSACTIONID
                             INNER JOIN ITEMCOMPANY IC
                                ON IC.ITEMCODE = STD.ITEMCODE
                             INNER JOIN ITEMCATEGORY C
                                ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
                              LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
                                ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
                               AND ISUB.ITEMSUBCATEGORY1ID IN
                                   (SELECT ITEMSUBCATEGORY1ID
                                      FROM ITEMSUBCATEGORY1
                                     WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
                             INNER JOIN STORE SE
                                ON SE.STORECODE = ST.STORECODE
                             WHERE ST.STORECODE = IV_STORECODE
                               AND SE.HOSPITALID = IV_HOSPITALID
                               AND TRUNC(ST.CREATEDDATE) BETWEEN V_FROMDATE AND
                                   V_TODATE
                               AND ST.STATUS <> 99
                               AND STD.ITEMCODE NOT LIKE '%#%'
                               AND                   
                                   (IV_DRUGTYPE IS NULL OR
                                   IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
                            UNION
                            SELECT D.STORECODE,
                                   TO_CHAR(D.ITEMCODE) AS ITEMCODE,
                                   C.ITEMCATEGORYNAME,
                                   ISUB.ITEMSUBCATEGORY1NAME
                              FROM DAILYINVENTORY D
                             INNER JOIN ITEMCOMPANY IC
                                ON IC.ITEMCODE = D.ITEMCODE
                             INNER JOIN ITEMCATEGORY C
                                ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
                              LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
                                ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
                               AND ISUB.ITEMSUBCATEGORY1ID IN
                                   (SELECT ITEMSUBCATEGORY1ID
                                      FROM ITEMSUBCATEGORY1
                                     WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
                             INNER JOIN STORE SE
                                ON SE.STORECODE = D.STORECODE
                             WHERE D.STORECODE = IV_STORECODE
                               AND SE.HOSPITALID = IV_HOSPITALID
                               AND TRUNC(D.UPDATEDDATE) <= V_TODATE
                               AND D.QTY > 0
                               AND D.ITEMCODE NOT LIKE '%#%'
                               AND C.ITEMCATEGORYID = IV_ITEMCATEGORY
                                  AND (IV_DRUGTYPE IS NULL OR
                                   IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
                               AND (IV_SUBITEMCATEGORY IS NULL OR
                                   ISUB.ITEMSUBCATEGORY1ID = IV_SUBITEMCATEGORY) Will post the explain plan ..
    Thanks in advance..

    Ensure you also include all the other information people will need to help you, e.g. database version, table structures/relationships and cardinalities, row counts etc.
    See the two threads linked to in the FAQ: {message:id=9360003}

  • Efficient way to read through big explain plan and genterate html explain plan for sql id's executed in past

    Hi,
    I have a sql which is recently having a performance problems in Production. I have generated a explain plan for it trying to find out what it is doing but plan itself is close to 1000 lines. I want to check if there is any efficient way to go through big plan like this one and quickly find the damaging areas..
    2) I also wanted to know if there is way to generate explain plans in HTML format which executed in past and have entry in dba_hist_sqltext.
    3) I also have two sql_monitor reports which I want to compare. is there any efficient way to do it as well?
    Please share your thoughts!
    Thanks in advance!
    Regards,
    Suman-

    Hi,
    I suggest you can try running sql advisor on the query maybe something fruitful comes up
    http://www.oracle-base.com/articles/11g/sql-access-advisor-11gr1.php
    I am not sure about the explain plan being printed in html format but
    You may also want to try the sqlhistory.sql query from below page
    http://evdbt.com/scripts/
    I have used it many times to check on executions and explain plans which may have changed over the period
    I have faced it many times , the query picks up a bad explain plan and performs poorly

Maybe you are looking for