PL/SQL Looping Statement

Advertisements

PLSQL Conditional Statement PLSQL Procedure

PL/SQL Looping Statement

Set of instructions given to the compiler to execute set of statements until condition becomes false is called loops. The basic purpose of loop is code repetition that means same code repeated again and again. There are three types of loops in pl-sql;

  • Simple loop
  • While loop
  • For loop

Simple loop

A Simple Loop is used when a set of statements is to be executed at least once before the loop terminates. An exit condition must be specified in the loop body, otherwise the loop will get into an infinite number of iterations. When the exit condition is satisfied the process exits from the loop body.

Syntax

variable initialize

loop
statements;
exit;
{or exit when condition; }

end loop;

Must be follow below steps;

  • Initialize a variable before the loop body.
  • Increment the variable in the loop body.
  • Use exit when statement to exit from loop body. If you use exit without when condition statement will be execute only once.

while loop

Syntax

variable initialize

while (condition)
statements;
end loop;

Must be follow below steps;

  • Initialise a variable before the loop body.
  • Increment the variable in the loop body.

for loop

A for loop is used to execute a set of statements for a predetermined number of times.

for loop in plsql

Syntax

for variable in initial_value .. final_value

loop

statements;

end loop;

Print Hello word five times

Example

begin
for i in 1 .. 4 loop
dbms_output.put_line("Hello");
end loop;
end;

Output

Hello
Hello
Hello
Hello
Hello

PLSQL Conditional Statement PLSQL Procedure

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements