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
Declaring and Initializing Objects: An object type is once defined and installed in the schema; you can use it to declare the objects in any PL/SQL, subprogram, block or packa

Dynamic Ranges The PL/SQL lets you determine the loop range dynamically at run time, as the example below shows: SELECT COUNT(empno) INTO emp_count FROM emp; FOR i IN 1..emp_cou

IF Statement The IF statement executes a series of statement conditionally. Whether the series is executed or not depends on the value of the Boolean expression. Syntax:

Using EXCEPTION_INIT To handle unnamed internal exceptions, you should use the OTHERS handler or the pragma EXCEPTION_INIT. The pragma is a compiler directive that can be th

What Is a Collection The collection is an ordered group of elements, all of similar type (for e.g. the grades for a class of students). Each element has a unique subscript whic

Using Pragma RESTRICT_REFERENCES: The function called from the SQL statements should obey certain rules meant to control the side effects. To check for violation of the rules,

Information Hiding   With the information hiding, you see only the details that are significant at a given level of algorithm and data structure design. The Information hiding

Project Description: This is stage 1 of a larger conversion project. We are converting a traditional Server/Client application written in Access 2007 into a web interface with S

Use the PLS_INTEGER Datatype When you require to declare an integer variable, use the datatype PLS_INTEGER that is the most efficient numeric type. That is as the PLS_INTEGER

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