Explain Plan for Query in a Stored Procedure

Use SQL Trace and TKPROF. For example, open SQL*Plus, and then issue the following code:-

alter session set tracefile_identifier = 'something-unique'
alter session set sql_trace = true;
alter session set events '10046 trace name context forever, level 8';

select 'right-before-my-sp' from dual;
exec your_stored_procedure

alter session set sql_trace = false;

Once this has been done, go look in your database's UDUMP directory for a TRC file with "something-unique" in the filename. Format this TRC file with TKPROF, and then open the formatted file and search for the string "right-before-my-sp". The SQL command issued by your stored procedure should be shortly after this section, and immediately under that SQL statement will be the plan for the SQL statement.

Edit: For the purposes of full disclosure, I should thank all those who gave me answers on this thread last week that helped me learn how to do this.

Tags:

Oracle