Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 







Estimate Rows Returned by SQL

Oracle Database Tips by Donald BurlesonMay 18, 2015

Question:  My application is an ad hoc query system and I want to estimate the number of rows returned by a SQL statement before running the SQL.  I know that this is the cardinality (rows returned estimates) for the SQL statement, but I need to know how to programmatically check the plan_table before running the query.  How can I estimate the size of the SQL result set? 

Answer:  To estimate the number of rows that the optimizer thinks that a query will return, you can use the explain plan syntax and read the plan_table for the cardinality column.  Each use in the application will need a plan_table:

SQL> CONN sys/password AS SYSDBA

SQL> @$ORACLE_HOME/rdbms/admin/utlxplan.sql

Table created.

SQL> GRANT ALL ON sys.plan_table TO public;

Grant succeeded.

SQL> CREATE PUBLIC SYNONYM plan_table FOR sys.plan_table;

Synonym created.

At this point, your application can populate the plan_table with the cardinality estimates:

SQL> explain plan set statement_id='estimate_rows' for select stuff from mmytab where myval = 12;  


Now, you can query the plan table.  You can modify this standard query to get the cardinality for the last step of the execution plan, which will display the estimated number of rows returned for the SQL statement:

select lpad(' ',2*level)||operation||' '||options||' '||object_name||
            ' PARTS('||partition_start||'-'||partition_stop||')')||
            decode(level,1,'  [Cost = '||Cost||']',Null) QUERY_PLAN,
        Object_Node, Other_Tag
from plan_table
where statement_id = 'estimate_rows'
connect by prior statement_id = statement_id and
            prior id = parent_id
start with id = 1
order by statement_id;

Please note:  The estimates for the number of rows returned will only be as current as your optimizer statistics as gathered by your dbms_stats utility.

Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.




Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster