Looking for a Tutor Near You?

Post Learning Requirement »
x

Choose Country Code

x

Direction

x

Ask a Question

x

x
x
x
Hire a Tutor

ORACLE PLSQL - Loops

Loading...

Published in: Oracle Training
944 Views

This document discuss about various Loops in PL/SQL like FOR LOOP, WHile LOOP.

Debarun S / Kolkata

10 years of teaching experience

Qualification: B.Tech

Teaches: Computer, Mathematics, Science, Chemistry, Computer Science, Physics, School Level Computer, Defence Exams, IBPS, Insurance Exams, SSC Exams

Contact this Tutor
  1. In this chapter, we will discuss Loops in PL/SQL. There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages Conditional Code If condition is true Condition If condition is false PL/SQL provides the following types of loop to handle the looping requirements. Click the following links to check their detail. S.N0 1 2 3 Loop Type & Description PL/SOL Basic LOOP In this loop structure, sequence of statements is enclosed between the LOOP and the END LOOP statements. At each iteration, the sequence of statements is executed and then control resumes at the top of the loop. PL/SQL WHILE LOOP Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. PL/SOL FOR LOOP
  2. When the above code is executed at the SQL prompt, it produces the following result Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable. Nested loops in PL/SQL 4 You can use one or more loop inside any another basic loop, while, or for loop. Labeling a PL/SQL Loop PL/SQL loops can be labeled. The label should be enclosed by double angle brackets ( < < and > > ) and appear at the beginning of the LOOP statement. The label name can also appear at the end of the LOOP statement. You may use the label in the EXIT statement to exit from the loop. The following program illustrates the concept s: s: s: s: s: s: s: s: s: s: s: DECLARE i number (1 j number (1) BEGIN outer loop FOR i IN 1. .3 LOOP
  3. PL/SQL supports the following control statements. Labeling loops also help in taking the control outside a loop. Click the following links to check their details. S.N0 EXIT statement 1 Control Statement & Description The Exit statement completes the loop and control passes to the statement immediately after the END LOOP. CONTINUE statement 2 Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. GOTO statement 3 Transfers control to the labeled statement. Though it is not advised to use the GOTO statement in your program.