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

 
 Home
 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
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

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

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle PL/SQL If Statements

Oracle Database Tips by Donald Burleson

Proper IF Statements
Mike Ault

When using nested IF statements always place the IF logic that will be exercised most often first. An example would be the IF exit, usually programmers will place the various nested IF constructs that actually perform code operations first, even if they are rarely exercised, by placing the exit IF first the processing associated with the other IF processing is avoided.

This is especially true of IF constructs contained within LOOP structures. Using the PROFILER_CONTROL procedure as an example look at Figure 1.

PROCEDURE profiler_control(
start_stop IN VARCHAR2, run_comm IN VARCHAR2, ret OUT BOOLEAN) AS
ret_code INTEGER;
BEGIN
 ret_code:=dbms_profiler.internal_version_check;
  IF ret_code !=0 THEN
   ret:=FALSE;
  ELSIF start_stop NOT IN ('START','STOP') THEN
   ret:=FALSE;
  ELSIF start_stop = 'START' THEN
   ret_code:=DBMS_PROFILER.START_PROFILER(run_comment1=>run_comm);
   IF ret_code=0 THEN
    ret:=TRUE;
   ELSE
    ret:=FALSE;
   END IF;
  ELSIF start_stop = 'STOP' THEN
   ret_code:=DBMS_PROFILER.FLUSH_DATA;
   ret_code:=DBMS_PROFILER.STOP_PROFILER;
   IF ret_code=0 THEN
    ret:=TRUE;
   ELSE
    ret:=FALSE;
   END IF; 
  END IF;
END profiler_control;
 

Figure 1: The PROFILER_CONTROL Package

Notice that most of time the procedure will exit without generating an action, however, the exit is at the bottom of the IF-ELSIF stack. By rearranging the code and using a BOOLEAN as the go-no go we get a simplified, more efficient program as shown in Figure 2.

PROCEDURE profiler_control(
start_stop IN BOOLEAN, run_comm IN VARCHAR2, ret OUT BOOLEAN) AS
ret_code INTEGER;
BEGIN
  IF start_stop IS NULL THEN
  Ret:=TRUE;
  ELSIF start_stop THEN 
   ret_code:=dbms_profiler.internal_version_check;
   IF ret_code !=0 THEN
    ret:=FALSE;
   END IF;
  ELSIF start_stop AND ret_code=0 THEN
   ret_code:=DBMS_PROFILER.START_PROFILER(run_comment1=>run_comm);
   IF ret_code=0 THEN
    ret:=TRUE;
   ELSE
    ret:=FALSE;
   END IF;
  ELSIF NOT start_stop THEN
   ret_code:=DBMS_PROFILER.FLUSH_DATA;
   ret_code:=DBMS_PROFILER.STOP_PROFILER;
   IF ret_code=0 THEN
    ret:=TRUE;
   ELSE
    ret:=FALSE;
   END IF; 
  END IF;
END profiler_control;
 

Figure 2: New and Improved PROFILER_CONTROL

We make the code more efficient and reduce the amount of CPU cycles for all other packages that call PROFILER_CONTROL. If the IF construct involved in contained within a LOOP structure the savings can be substantial.

 
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.

 


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

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.