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
Data Types in SQL - Character CHARACTER or, synonymously, CHAR, for character strings. When this type is to be the declared type of something (e.g., a column), the permissible

Operators on Tables and Rows Row Extraction TUPLE FROM r, SQL has row subqueries. These are just like scalar subqueries except that they may specify more than one column.

Bulk Binds advantages In the Embedded Oracle RDBMS, the PL/SQL engines accept any valid PL/SQL subprogram or block. As the figure shows, the PL/SQL engine executes all procedur

Problem: (a) Define the following terms: (i) data mining. (ii) OLAP. (b) Differentiate between snowflake schema and star schema. Support your answer with appropriate

Create the four tables and populate them with the given data. Answer the following queries in SQL. 1. Get all part-color/part-city combinations. Note: Here and subsequently, the

ORIGIN OF EARTH - BIG-BAN G HYPOTHESIS - Origin of life is linked to origin of earth. Cosmos, the Universe originated 10-20 billion years ago by Big Bang (thermonu

Datatype Conversion At times it is necessary to convert a value from one datatype to another. For e.g. if you want to inspect a rowid, you should convert it to a character stri

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

Example of WHEN or THEN Constraints A concrete example showing how SQL supports WHEN/THEN constraints CREATE TABLE SAL_HISTORY (EmpNo CHAR (6), Salary INTEGER NOT NULL,

Parameter and Keyword Description: dynamic_string: This is a string variable, literal, or expression which represents a SQL statement or the PL/SQL block. define_vari