Exforsys.com
 
Home Tutorials Oracle 9i
 

Tutorial 9 : Oracle 9i: PL/SQL Control Structures

 

Tutorial 9 : Oracle 9i: PL/SQL Control Structures

Page 1 of 2
This tutorial teaches about how to structure flow of control through a PL/SQL program. The control structures of PL/SQL are simple yet powerful. Control structures in PL/SQL can be divided into selection or conditional, iterative and sequential.

<

 

Sponsored Links

 


Control Structures

This chapter teaches about how to structure flow of control through a PL/SQL program. The control structures of PL/SQL are simple yet powerful. Control structures in PL/SQL can be divided into selection or conditional, iterative and sequential.

Conditional Control (Selection): This structure tests a condition, depending on the condition is true or false it decides the sequence of statements to be executed. Example
IF-THEN, CASE and searched CASE statements.

Syntax for IF-THEN

IF THEN
Statements
END IF;

Example:



IF-THEN-ELSE:


IF THEN


Statements


ELSE


statements


END IF;



Example:




IF-THEN-ELSIF:

IF THEN


Statements


ELSIF THEN


Statements


ELSE


Statements


END IF;



 


Iterative Control


LOOP statement executes the body statements multiple times. The statements are placed between LOOP – END LOOP keywords.


The simplest form of LOOP statement is an infinite loop. EXIT statement is used inside LOOP to terminate it.


Syntax for LOOP- END LOOP



LOOP


Statements


END LOOP;


Example:



BEGIN


LOOP


DBMS_OUTPUT.PUT_LINE (‘Hello’);


END LOOP;


END;



<

 

Sponsored Links

 


Labeling Loops

We can label Loops. A Label is undeclared identifier enclosed between double angle brackets( Ex. <>). The following example demonstrates usage of labels in loops.


Next Page: Tutorial 9 : Oracle 9i: PL/SQL Control Structures - Page 2


Read Next: Tutorial 10: Oracle 9i : Cursors



 

 

Comments


Narendra Reddy said:

  I have completed working with control structures thoroughly....
July 20, 2007, 2:34 am

Jimbo888 said:

  Can i have sub-loops in PL/SQL? like a loop inside a LOOP??
December 14, 2008, 11:04 am

raghu said:

  this is best tutorial...in real
best..........its great
December 19, 2008, 2:13 pm

Krishna Mohan said:

  Super site to learn PL/SQL.
It had clarified most of my doubts on the subject.
August 27, 2010, 1:11 pm

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

 
 


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape