1. To Display even numbers till n
SQL> DECLARE
2 I NUMBER:= &I;
3 CNT NUMBER:=1;
4 BEGIN
5 WHILE(CNT <= I) LOOP
6 IF(MOD(CNT,2)=0) THEN
7 DBMS_OUTPUT.PUT_LINE(CNT);
8 END IF;
9 CNT:=CNT+1;
10 END LOOP;
11 END;
Enter value for i: 10
2
4
6
8
10
PL/SQL procedure successfully completed.
OR
2. To Display n even numbers
SQL> DECLARE
2 OP NUMBER:= 2;
3 I NUMBER:=&I;
4 BEGIN
5 WHILE(I>0) LOOP
6 IF(MOD(OP,2)=0)THEN
7 DBMS_OUTPUT.PUT_LINE(OP);
8 END IF;
9 I:=I-1;
10 OP:=OP+2;
11 END LOOP;
12 END;
Enter value for i: 10
2
4
6
8
10
12
14
16
18
20
PL/SQL procedure successfully completed.
0 Comments