PL-SQL
Oracle PL/SQL Object Types Tutorial with EXAMPLES
What is Object Type in PL/SQL? Object-Oriented Programming is especially suited for building...
WHILE loop statement works similar to the Basic loop statement except the EXIT condition is at the very beginning of the loop.
It works like an entry-check loop in which execution block will not even be executed once if the condition is not satisfied, as the exit condition is checking before execution part. It does not require keyword 'EXIT' explicitly to exit from the loop since it is validating the condition implicitly each time of the loop.
WHILE <EXIT condition> LOOP <execution block starts> . . . <execution_block_ends> END LOOP;Syntax Explanation:
Example 1: In this example, we are going to print number from 1 to 4 using WHILE loop statement. For that, we will execute the following code.
DECLARE
a NUMBER :=1;
BEGIN
dbms_output.put_line('Program started');
WHILE (a <= 5)
LOOP
dbms_output.put_line(a);
a:=a+1;
END LOOP;
dbms_output.put_line(‘Program completed' );
END:
/
Code Explanation:
| Loop | WHILE Loop |
| EXIT Criteria | Exit when the check condition returns false |
| Usage | Good to use when the loop count is unknown, and exit is based on some other condition. |
What is Object Type in PL/SQL? Object-Oriented Programming is especially suited for building...
What is Nested Blocks Oracle? In PL/SQL, each block can be nested into another block. They are...
What is For Loop? "FOR LOOP" statement is best suitable when you want to execute a code for a...
What is Collection? A Collection is an ordered group of elements of particular data types. It can...
In this tutorial, you are going to see the detailed description on how to create and execute the...
What are TCL Statements in PL/SQL? TCL stands for Transaction Control Statements. It will either save...