Exit-when - iterative control, PL-SQL Programming

EXIT-WHEN

The EXIT-WHEN statement permits a loop to complete conditionally. Whenever the EXIT statement is encountered, the condition in the WHEN clause is computed. When the condition is true, the loop completes and controls the passes to the next statement after the loop. An illustration is as shown below:

LOOP
FETCH c1 INTO...
EXIT WHEN c1%NOTFOUND; -- exit loop if condition is true
...
END LOOP;
CLOSE c1;


Until the condition is true, the loop cannot complete. Thus, a statement inside the loop should change the value of the condition. In the last illustration, if the FETCH statement returns a row, then the condition is false. When the FETCH statement fails to return a row, then the condition is true, the loop completes, and then control passes to the CLOSE statement. The EXIT-WHEN statement replaces a simple IF statement. For illustration, compare the following statements as:



IF count > 100 THEN        | EXIT WHEN count > 100;
EXIT;                                   |
END IF;                               |


These statements are logically equal, but the EXIT-WHEN statement is easier to understand and read.

Posted Date: 10/3/2012 5:47:29 AM | Location : United States







Related Discussions:- Exit-when - iterative control, Assignment Help, Ask Question on Exit-when - iterative control, Get Answer, Expert's Help, Exit-when - iterative control Discussions

Write discussion on Exit-when - iterative control
Your posts are moderated
Related Questions
IN Operator The operator IN tests the set membership. This means "equal to any member of." The set may have nulls, but they are ignored. For illustration, the statement below do

Using raise_application_error The Package DBMS_STANDARD that is supplied with Oracle gives language facilities that help your application to interact with Oracle. For illustra

Ensuring Backward Compatibility   The PL/SQL Version 2 permits some abnormal behavior which Version 8 disallows. Particularly, Version 2 permits you to (i) Make the forw

THEORY OF BIOGENESIS - This theory explains that the existing living organisms originated from pre-existing living beings not from non living entities. This concept of or

Product-specific Packages The Oracle and different Oracle tools are supplied with the product-specific packages which help you to build the PL/SQL-based applications. For illus

Using PRIOR and NEXT The PRIOR(n) returns the index number that precede index n in a collection. The NEXT(n) returns the index number which succeed the index n. If n has no pr

Great Plains (Microsoft Dynamics) Purchases Report Project Description: I want to build a purchases report that matches the General Ledger. presently, when I join the PM20

What Are Subprograms? The Subprograms are named PL/SQL blocks which can take parameters and be invoked. The PL/SQL has 2 types of subprograms known as the procedure s and func

Project Description: We organize an online system called ACPAS we have created a project called EVO that can be use by our customers to integrate their web sites with the Acpas

GOTO Statement   The GOTO statement branches categorically to a block label or statement label. The label should be exclusive within its scope and should precede a PL/SQL bloc