write program in pl/sql to print series 2 ,4, 6, 8, 10 using BASIC loop.
Answers
Answer:
- Between the LOOP and END LOOP statements is a sequence of statements that makes up a basic loop structure.
- The series of statements are carried out on each iteration before control returns to the loop's beginning.
program in pl/sql to print series 2 ,4, 6, 8, 10 using BASIC loop
set serveroutput on;
DECLARE
i int;
BEGIN
i := 0;
LOOP
i := i+2
dbms_output.put_line(i);
exit WHEN x > 10
END LOOP;
END;
Output:
2
4
6
8
10
#SPJ3
Answer:
In PL/SQL, loops offer a mechanism to repeatedly run a certain section of a programme or a code statement whatever often is necessary. When it is unclear how often a piece of code will be repeated, a basic loop or simple loop is recommended in PL/SQL code. The code block will run at least once when we utilize the basic loop.
Explanation:
Two things should be kept in mind when utilizing it:
- The words LOOP and Finish LOOP are always used to start and end a simple loop, respectively.
- Using the exit statement or the exit when statement, a basic/simple loop can be stopped at any time by defining a condition.
syntax:
LOOP
sequence of statements
END LOOP;
The loop in the program below is used to output numbers from 2 to 8 on the terminal, and the exit command is used to end the loop. Let's look at one more instance where the exit when statement will be used to end the loop.
Program:
set serveroutput on;
DECLARE
i int;
BEGIN
i := 0;
LOOP
i := i+2
dbms_output.put_line(i);
exit WHEN x > 10
END LOOP;
END;
Output:
2
4
6
8
10
#SPJ3