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
Explicit Cursor Attributes The cursor variable or each cursor has four attributes: %FOUND, %ISOPEN, %ROWCOUNT, and %NOTFOUND. When appended to the cursor or cursor variable, th

%NOTFOUND The %NOTFOUND is the logical opposite of the %FOUND. The %NOTFOUND yields TRUE when an INSERT, UPDATE, or DELETE statement affected no rows, or the SELECT INTO state

Implicit Rollbacks Before execute the INSERT, UPDATE, or DELETE statement, the Oracle marks an implicit savepoint . When the statement fails, the Oracle rolls back to the save

%ROWCOUNT The %ROWCOUNT yields the number of rows affected by the INSERT, UPDATE, or DELETE statement, or returned by a SELECT INTO statement. The %ROWCOUNT yields zero when a

Relational Operators and Logical Operators It prepares the ground for subsequent sections in which each specific relational operator is paired with its logical counterpart, su

Project Description: I want somebody who can help me with an idea that I have been working on for a few months now. The person will require extensive knowledge of warcraft 3 PvP

This is a Customer Management project. Customer data is presented in a text file. The program will load this text data into its DB columns. The data mapping is user definable. User

Parameter Default Values As the illustration below shows, you can initialize the IN parameters to the default values. In that way, you can pass various numbers of actual par

Using EXISTS The EXISTS(n) returns TRUE if the nth element in a collection exist. Or else, EXISTS(n) returns FALSE. Primarily, you use EXISTS with DELETE to maintain the spars

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 illu