0% found this document useful (0 votes)
31 views

PLSQL 1

This document describes a PL/SQL procedure to calculate the area of geometric shapes (triangle, circle, square) by passing parameters to sub-procedures. It also includes sample code to calculate the factorial of a number and to find the total marks, average, and grade of students by iterating through a database table using a cursor. The procedures demonstrate how to perform calculations and update/output data using PL/SQL blocks and sub-procedures.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

PLSQL 1

This document describes a PL/SQL procedure to calculate the area of geometric shapes (triangle, circle, square) by passing parameters to sub-procedures. It also includes sample code to calculate the factorial of a number and to find the total marks, average, and grade of students by iterating through a database table using a cursor. The procedures demonstrate how to perform calculations and update/output data using PL/SQL blocks and sub-procedures.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PROCEDURE

11. To write PL/SQL program to calculate area of triangle, circle and square using procedure.

SET SERVEROUTPUT ON

DECLARE

l number;

b number;

r number;

h number;

pi float;

squ number;

tri number;

cir number;

procedure triangle(b in number, h in number)

as

begin

tri:=0.5*b*h;

dbms_output.put_line('area of triangle:'||tri);

end;

procedure circle(r in number)

as

begin

pi:=3.14;

cir:=pi*r*r;

dbms_output.put_line('area of circle:'||cir);
end;

procedure square(l in number)

as

begin

squ:=l*l;

dbms_output.put_line('area of square:'||squ);

end;

begin

l:=5;

b:=5;

h:=2;

r:=5;

triangle(l,b);

circle(r);

square(h);

end;

OUTPUT:

Area of triangle:25

Area of circle:78.5

Area of square:4
12. To write PL/SQL program to find the factorial of given number using procedure.

SET SERVEROUTPUT ON

declare

n number(2);

p number(5);

i number(2);

begin

n:=&n;

p:=1;

for i in 1..n

loop

p:=p*i;

end loop;

dbms_output.put_line(‘Factorial value is ‘ || to_char(p));

end;

OUTPUT:

ENTER VALUE 5

Factorial value is 120


13. Creation of Students Information table and write PL/SQL Block to find the Total,
Average marks and Results.

Program

SQL> create table studres(regno number(4) primary key, name varchar(20), paper1 number(2),
paper2 number(2), paper3 number(2), paper4 number(2));
Table created
SQL> insert into studres values(1001,’mini’, 23, 49, 44, 46);
1 row created
SQL> insert into studres values(1002,’safeer’, 40, 30, 20, 10);
1 row created
SQL> insert into studres values(1003,’baby’, 49, 39, 46, 45);
1 row created
SQL> insert into studres values(1004,’danish’, 40, 10, 20, 22);
1 row created

SQL> insert into studres values(1005,’swetha’, 20, 18, 20, 15);


1 row created
SQL> alter table studres add( averg number(5,2), grade varchar(2));
Table altered
SQL> declare
2 cursor c is select * from studres;
3 v_avg studres.averg %type;
4 v_tot studres.tot%type;
5 v_grade studres.grade%type;
6 begin
7 for i in c loop
8 v_tot = i.paper1+i.paper2+i.paper3+i.paper4;
9 v_avg=v_tot/2;
10 if(v_avg>=85) then
11 v_grade:=’A’
12 elsif (v_avg>=65) then
13 v_good:=’B’;
14 elsif(v_avg>=40) then
15 v_grade:=’C’;
16 elsif(v_avg>=25) then
17 v_grade:=’D’;
18 else
19 v_grade:=’E’;
20 end if ;
21 update studres set averg=v_avg, grade=v_grad, where regno=i.regno;
22 end loop;
23 end;
24 /
PL/SQL procedure successfully completed
SQL> select* from studres;
REGNO NAME PAPER1 PAPER2 PAPER3 PAPER4 AVERG GRADE
1001 mini 23 49 44 46 40.5 C
1002 safeer 40 30 20 10 25 D
1003 baby 49 39 46 45 44.75 C
1004 danish 40 10 20 22 23 E
1005 swetha 20 18 20 15 18.25 E

You might also like