DBMS Lab- 7 PLSQL - 1
DBMS Lab- 7 PLSQL - 1
Syntax:
WHILE <condition(s)>
LOOP
<Statement(s)>;
END LOOP;
Note: EXIT statement can be used to terminate the loop based on a condition
Program to illustrate EXIT statement in while loop
Declare
V_no number (3):=1;
Begin
While V_no<=10
Loop
Dbms_output.put_line (V_no);
V_no:=V_no+1;
If V_no=5
Then Exit;
END IF;
End Loop;
Dbms_output.put_line ('Out of loop');
End;
/
Program to illustrate for loop
Begin
For V_no in 1..10
Loop
If mod(V_no,2)=0
Then Dbms_output.put_line (V_no);
END IF;
End Loop;
End;
/
EXERCISE
1. Write a PLSQL program to compute the Factorial of a given number and display it
2. Write a PLSQL program to display the first ‘n’ digits of the Fibonacci series
3. Write a PLSQL program to read a number and display if it is prime or not
4. Write a PLSQL program to read a number and display if it is an armstrong number or not
experimental Viva Questions: