FACTORIAL VALUE
declare
fact number(5):=1;
n number(4):=5;
begin
for i in 1..5 loop
fact:=fact*i;
end loop;
dbms_output.put_line(fact);
end;
Output:
120
REVERSE NUMBER
declare
num number;
rev_num number:=0;
begin
num:=87654321;
while num>0
loop
rev_num:=(rev_num*10)+mod(num,10);
num:=trunc(num/10);
end loop;
dbms_output.put_line('reverse number is'||rev_num);
end;
Output:
reverse number is12345678
VOTING ELIGIBLE
declare
age number(3):=20;
begin
if age>18 then
dbms_output.put_line('eligible for vote');
else
dbms_output.put_line('not eligible for vote');
end if;
end;
Output:
eligible for vote
ELECTRICITY BILL
declare
unit_consumed number(4):=500;
bill_amount number(4):=0;
begin
unit_consumed:=250;
if unit_consumed<=100 then
bill_amount:=unit_consumed*1.50;
elsif unit_consumed<=200 then
bill_amount:=100*1.50+(unit_consumed-100)*2.50;
else
bill_amount:=100*1.50+100+2.50+(unit_consumed-200)*2.50;
end if;
dbms_output.put_line('electricity bill in Rs'|| bill_amount);
end;
/
Output:
electricity bill in Rs378