Aim - PL/SQL program to print 1 to 10 using basic loop.
Sample Program: -
declare num number(3); begin num:=1; loop dbms_output.put_line(num); num:=num+1; exit when num>10; end loop; end;
Output: -
1
2
3
4
5
6
7
8
9
10
declare num number(3); begin num:=1; loop dbms_output.put_line(num); num:=num+1; exit when num>10; end loop; end;
FOR variable IN start..end LOOP PL/SQL block statements END LOOP;
declare num number(3); begin for num in 1..10 loop dbms_output.put_line(num); end loop; end;
declare num number(3); begin for num in REVERSE 1..10 loop dbms_output.put_line(num); end loop; end;
declare
num number(5);
begin
num:=#
if num mod 2 =0 then
dbms_output.put_line('Accepted Number '||num||' is even');
else
dbms_output.put_line('Accepted Number '||num||' is odd');
end if;
end;
declare
a number(3);
b number(3);
c number(3);
avgr number(5,2);
begin
a:=&a;
b:=&b;
c:=&c;
avgr:=((a+b+c)/3);
dbms_output.put_line('Average of a, b, c is: '||avgr);
end;
Output of PL SQL Block: -
Enter value for a: 22
old 7: a:=&a;
new 7: a:=22;
Enter value for b: 32
old 8: b:=&b;
new 8: b:=32;
Enter value for c: 43
old 9: c:=&c;
new 9: c:=43;
Average of a, b, c is: 32.33