0% found this document useful (0 votes)
276 views5 pages

SQL Programs

The document contains 16 PL/SQL programs with examples of calculating the average of numbers, area of shapes, interest calculations, determining even/odd numbers, checking leap years, finding maximum numbers, generating series, and other mathematical computations. The programs demonstrate the use of basic PL/SQL structures like variables, conditional statements, loops, and built-in functions to perform various numeric and logical operations.

Uploaded by

Subramanya Dg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
276 views5 pages

SQL Programs

The document contains 16 PL/SQL programs with examples of calculating the average of numbers, area of shapes, interest calculations, determining even/odd numbers, checking leap years, finding maximum numbers, generating series, and other mathematical computations. The programs demonstrate the use of basic PL/SQL structures like variables, conditional statements, loops, and built-in functions to perform various numeric and logical operations.

Uploaded by

Subramanya Dg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

PL/SQL Program to find average of three numbers


Declare
a number;
b number;
c number;
avgr number;
Begin
a:=&a;
b:=&b;
c:=&c;
avgr:=(a+b+c)/3;
dbms_output.put_line('Average of number is: ' || avgr);
End;
2. PL/SQL Program to find area of circle
Declare
r number;
p number:=3.142;
area number;
cir number;
Begin
r:=&r;
area :=p*r*r;
cir:=2*p*r;
dbms_output.put_line('Area of circle is : ' || area);
dbms_output.put_line('Circumference of circle is : ' || cir);
End;
3. PL/SQL Program to simple interest
Declare
p number;
r number;
t number;
si number;
tot number;
begin
p:=&p;
r:=&r;
t:=&t;
si :=(p*r*t)/100;
tot:=si+p;
dbms_output.put_line('Simple interest is : ' || si);
dbms_output.put_line('Total amount is : ' || tot);
end;

4. PL/SQL Program to compound interest


Declare
p number;
r number;
t number;
ci number;
tot number;
begin
p:=&p;
r:=&r;
t:=&t;
ci :=p*(1+r/100)**t-p;
tot:=ci+p;
dbms_output.put_line('Compound interest is : ' || ci);
dbms_output.put_line('Total amount is : ' || tot);
end;
5. PL/SQL Program to find area of triangle
Declare
b number;
h number;
area number;
begin
b:=&b;
h :=&h;
area:=1/2*b*h;
dbms_output.put_line('Area of triangle is : ' || area);
end;
6. PL/SQL Program given number is even or odd
Declare
num number;
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;
7. PL/SQL Program Leap year
Declare
y number;
Begin
y:=&y;
if y mod 4 =0 then
dbms_output.put_line('Year '|| y ||' leap year');
else
dbms_output.put_line('Year '|| y ||' not leap year');
end if;
End;

8. PL/SQL Program biggest 3 number


Declare
A number;
B number;
C number;
Big number;
Begin
a :=&a;
b :=&b;
c :=&c;
if a > b and a > c then
big :=a;
else if b > a and b > c then
big:=b;
else
big:=c;
end if;
end if;
dbms_output.put_line('Biggest number is '||big);
End;
9. PL/SQL Program Commission of salesmen
Declare
n char(10):=Mr. DGS;
sales number;
com number;
Begin
sales:=&sales;
if sales >=50000 then
com:=sales*5/100;
elsif sales >=25000 then
com:=sales*3/100;
elsif sales >=10000 then
com:=sales*1/100;
else
com:=0;
end if;
dbms_output.put_line('Salesmen Name
dbms_output.put_line('Sales is

'|| sales );

dbms_output.put_line('Commission is
End;

'|| n );

'|| com );

10.

PL/SQL program to print 1 to 10 number using FOR loop

declare
num number(3);
begin
dbms_output.put_line(Numbers are);
for num in 1..10 loop
dbms_output.put_line(num);
end loop;
end;
11.

Program to print 1 to 10 in reverse order using FOR loop.

declare
num number(3);
begin
for num in REVERSE 1..10 loop
dbms_output.put_line(num);
end loop;
end;
12.

PL/SQL program to generate Fibonacci series.

declare
f1 number(3);
f2 number(3);
f3 number(3);
num number(3);
begin
f1:=0;
f2:=1;
f3:=0;
num:=1;
while num<=10
loop
dbms_output.put_line(f3);
f1 :=f2;
f2:=f3;
f3:=f1+f2;
num:=num+1;
end loop;
end;

13. Write a PL/SQL to find the greater no among three numbers.


Declare
a number;
b number;
c number;
Begin
a:=&a;
b:=&b;
c:=&c;
if a>b and a>c then
dbms_output.put_line(a||'is greater');
elsif b>a and b>c then
dbms_output.put_line(b||'is greater');
elsif c>a and c>b then
dbms_output.put_line(c||'is greater');
end if;
end;
14. PL/SQL Program to calculate Factorial of number
Declare
num number :=#
fact number :=1;
begin
for i in 1..v_num
loop
fact:=fact*i;
end loop;
dbms_output.put_line('fact of '||num||' is '||fact);
end;
15. Program to calculate Even or odd Number
declare
n number;
r number :=1;
begin
n:=&number;
for r in 1..n
loop
if mod(r,2)=0 then
dbms_output.put_line('Even No :' || r);
end if;
end loop;
end;
16. Multiplication Table
DECLARE
n number := &n;
prod number;
BEGIN
for i in 1..10 loop
prod := n * i;
dbms_output.put_line(n||' * '||lpad(i,2,' ') ||' = '||lpad(prod,3,'
'));
end loop;
END;

You might also like