While-loop - iterative control, PL-SQL Programming

Assignment Help:

WHILE-LOOP

The WHILE-LOOP statement relates a condition with the series of statements enclosed by the keywords LOOP and END LOOP, as shown:

WHILE condition LOOP
sequence_of_statements
END LOOP;

Before each of the iteration of the loop, the condition is computed. If the condition is true, then the series of statements is executed, then the control resumes at the top of the loop. When the condition is false or null, the loop is then bypassed and control passes to the next statement. An illustration is shown below:

WHILE total <= 25000 LOOP
...
SELECT sal INTO salary FROM emp WHERE...
total := total + salary;
END LOOP;

The number of iterations depends on the condition and is not known until the loop done. The condition is tested at the top of the loop, so the series might execute zero times. In the last illustration, if the initial value of total is bigger than 25000, the condition is false and the loop is bypassed.

A few languages have a LOOP UNTIL or REPEAT UNTIL structure, that tests the condition at the bottom of the loop rather than at the top. So, the sequence of the statements is executed at least once. The PL/SQL has no such structure, but you can easily build one, as shown:

LOOP
sequence_of_statements
EXIT WHEN boolean_expression;
END LOOP;

To make sure that a WHILE loop executes at least once, then use an initialized Boolean variable in the condition which is as shown below:

done := FALSE;
WHILE NOT done LOOP
sequence_of_statements
done := boolean_expression;
END LOOP;


The statement inside the loop should assign a new value to the Boolean variable. Or else, you have an infinite loop. For illustration, the following LOOP statements are logically equal:

WHILE TRUE LOOP | LOOP
... | ...
END LOOP; | END LOOP;


Related Discussions:- While-loop - iterative control

%found - implicit cursor attributes, %FOUND Until the SQL data manipul...

%FOUND Until the SQL data manipulation statement is executed, the %FOUND yields NULL. Afterward, the %FOUND yields TRUE, when an INSERT, UPDATE, or DELETE statement affected o

Exception_init pragma - pl/sql, EXCEPTION_INIT Pragma The pragma EXCEPT...

EXCEPTION_INIT Pragma The pragma EXCEPTION_INIT relates an exception name with an Oracle error number. Which allow you to refer to any internal exception by the name and to wri

Indeterminacy in sql, Indeterminacy in SQL Some SQL expressions are ac...

Indeterminacy in SQL Some SQL expressions are actually not function invocations at all in the mathematical sense, being indeterminate-invocations operating on identical input

Using savepoint, Using SAVEPOINT The SAVEPOINT names and marks the pre...

Using SAVEPOINT The SAVEPOINT names and marks the present point in the processing of a transaction. Used with the ROLLBACK TO statement, the savepoints undo parts of a transac

Subprograms, Subprograms The PL/SQL has two types of subprograms known ...

Subprograms The PL/SQL has two types of subprograms known as the procedures and functions that can take parameters and be invoked. As the following example represents, a subp

Object type in pl/sql, Object Type: The object type is a user-define...

Object Type: The object type is a user-defined composite datatype which encapsulates a data structure along with the functions and procedures required to manipulate the data

program for employees -ado.net framework , Challenge 1 You are require...

Challenge 1 You are required to do the project and write a test plan for it. Demo 4 is a check writer program for employees. In it, the user enters all information about the

If statement - syntax, IF Statement The IF statement executes a series ...

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:

Appgen to sap data export, We are seeking a freelance consultant that is fa...

We are seeking a freelance consultant that is familiar with Appgen applications. We require exporting all our data into a format appropriate for importing into SAP Business One. Pl

Comparison operators - sql operators, Comparison Operators Usually, yo...

Comparison Operators Usually, you use the comparison operators in the WHERE clause of a data manipulation statement to form the predicates, that compare one expression to anot

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd