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
Functions   The function is a subprogram that calculates a value. The Functions and procedures are structured similar, except that the functions have a RETURN clause. You can

Opening a Cursor Variable The OPEN-FOR statement relates a cursor variable with the multi-row query, executes the query, and then identifies the result set. The syntax for ope

At times, customers make mistakes in submitting their orders and call to cancel the order. Brewbean’s wants to create a trigger that automatically updates the stock level of all pr

User-Defined Exceptions The PL/SQL defines the exceptions of your own. Dissimilar to the predefined exceptions, the user-defined exceptions should be declared and should be rai

Count Operator in SQL Example: Counting the students who have scored more than 50 in some exam (SELECT COUNT (*) FROM (SELECT DISTINCT StudentId FROM EXAM_MARK WHE

Important Distinctions The list of important distinctions are given below: Value versus variable Syntax versus semantics Variable versus variable reference

Attributes: Just similar to variable, an attribute is declared with a name and datatype. The name should be exclusive within the object type. The datatype can be any Oracle ty

Advantages of Invoker Rights The Invoker-rights routines centralize the data retrieval. They are particularly helpful in applications which store data in various schemas. In su

Example of Null operator - NiNo Rule If we wanted to make HIGHER_OF adhere to "NULL in, NULL out"-let's call it the NiNo rule-we would have to write something like what is sho

Example of Cast Operator So long as CAST is used as shown, we could obtain the total marks for each exam in similar fashion, using SUM (Mark) AS TotalMarks. However, this giv