by Markus Winand.

Getting an Execution Plan


Viewing an execution plan, including actual measurements, in the Oracle database involves three steps:

  1. Activation of the measurements (optional)

  2. Executing the SQL statement

  3. Fetching the execution plan

Activation of the Measurements

To get all run-time statistics, such as the time for each operation, the collecting of these values must be activated first. This can be done in the respective statement by adding the hint /*+ GATHER_PLAN_STATISTICS */ or once in the session so that it affects all following executions.

alter session set statistics_level = 'ALL'

Executing the SQL Statement

Running the statement causes the execution plan to be cached (SQL area). If you activated the collection of run-time statistics, they will be added there as well.

select * from dual

If you like this page, you might also like …

… to subscribe my mailing lists, get free stickers, buy my book or join a training.

Fetching the Execution Plan

The package DBMS_XPLAN can show execution plans from the SQL area. The following example shows how to display the last execution plan that was executed in the current database session:

select * from table(dbms_xplan.display_cursor(null, null,
                                  'LAST ALLSTATS +COST'))

The query will display the execution plan as shown in the book:

---------------------------------------------------------------
| Operation         | Name | E-Rows | Cost | A-Rows | A-Time |.
---------------------------------------------------------------
| SELECT STATEMENT  |      |        |    2 |      1 |  00.01 |.
|  TABLE ACCESS FULL| DUAL |      1 |    2 |      1 |  00.01 |.
---------------------------------------------------------------

The execution plans shown here were edited for brevity.

Previous pageNext page

You can’t learn everything in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up. Have a look at modern-⁠sql.com as well.

About the Author

Photo of Markus Winand

Markus Winand provides insights into SQL and shows how different systems support it at modern-sql.com. Previously he made use-the-index-luke.com, which is still actively maintained. Markus can be hired as trainer, speaker and consultant via winand.at.

Buy the Book

Cover of “SQL Performance Explained”: Squirrel running on grass

The essence of SQL tuning in 200 pages

Buy now!
(paperback and/or PDF)

Paperback also available at Amazon.com.

Hire Markus

Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »

Connect with Markus Winand

Subscribe mailinglistsSubscribe the RSS feedMarkus Winand on LinkedInMarkus Winand on XINGMarkus Winand on TwitterMarkus Winand on Bluesky
Copyright 2010-2025 Markus Winand. All righs reserved.
Legal | Contact | NO WARRANTY | Trademarks | Privacy and GDPR