Skip to main content
Code and think

Oracle SQL Query plan for an executed query

Sometimes you want to check the query plan that your app executed it. In such case, you cannot use an SQL editor to get the plan. What you can do is to find sql_id of your query and check the plan that is stored in the DB.

select sql_id, sql_text 
from v$sql
where sql_text like '%AND MY_ID%';

Where "AND MY_ID" is as unique part of your query as possible. Once you found it, copy "SQL_ID" and paste it in the next query.

select plan_table_output 
from table(dbms_xplan.display_cursor('9tvx270mmh44t',null));

Where "9tvx270mmh44t" is ID copied from the previous query.

References:

https://blogs.oracle.com/optimizer/post/how-do-i-display-and-read-the-execution-plans-for-a-sql-statement

http://www.dba-oracle.com/t_sql_execution_plan_finished_query.htm

https://docs.oracle.com/database/121/ARPLS/d_xplan.htm#ARPLS378