Instance analysis of Oracle stored procedure loop syntax

Time:2020-10-26

This paper describes the Oracle stored procedure loop syntax. For your reference, the details are as follows:

1. Simple cycle

grammar


loop
  statements;
end loop;

example:


counter := 0;
loop
  counter := counter + 1;
  exit when counter = 5;
end loop;

Note: the exit statement immediately ends the loop, and the exit when statement stops the loop when the specified condition occurs (can appear anywhere in the loop code)

2. While loop

grammar


while condition loop
  statements
end loop;

example:


counter := 0;
while counter < 6 loop
  counter := counter + 1;
end loop;

3. For loop

grammar


for loop_variable in [reverse] lower_bound.. upper_bounder loop
  statements
end loop;

example:


for count2 in 1..5 loop
  DBMS_OUTPUT.PUT_LINE(count2);
end loop;

I hope this paper will be helpful to the Oracle database program design.

Recommended Today

Regular expression sharing for checking primes

This regular expression is shown as follows: Regular expressions for checking prime numbers or not To use this positive regular expression, you need to convert the natural number into multiple 1 strings. For example, 2 should be written as “11”, 3 should be written as “111”, 17 should be written as “11111111111”. This kind of […]