0% found this document useful (0 votes)
27 views3 pages

Group (A) 5

Uploaded by

surajs300303
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)
27 views3 pages

Group (A) 5

Uploaded by

surajs300303
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/ 3

Group A: Lab Assignment No.

TITLE: PL/SQL Stored Procedure and Stored Function.


Write a Stored Procedure namely proc_Grade for the categorization of
student. If marks scored by students in examination is <=1500 and
marks>=990 then student will be placed in distinction category if marks
scored are between 989 and900 category is first class, if marks 899 and
825 category is Higher Second Class.
Write a PL/SQL block for using procedure created with above
requirement.
Stud_Marks(name, total_marks)
Result(Roll,Name, Class)
Frame the separate problem statement for writing PL/SQL Stored
Procedure and function, inline with above statement. The problem
statement should clearly state the requirements.

mysql> create table result(roll_no int,name varchar(20),class varchar(20));


Query OK, 0 rows affected (0.02 sec)

mysql> insert into marks values('1','Abhi','1400');


Query OK, 1 row affected (0.01 sec)

mysql> insert into marks values('2','piyush','980');


Query OK, 1 row affected (0.01 sec)

mysql> insert into marks values('3','hitesh','880');


Query OK, 1 row affected (0.01 sec)

mysql> insert into marks values('4','ashley','820');


Query OK, 1 row affected (0.01 sec)

mysql> insert into marks values('5','partik','740');


Query OK, 1 row affected (0.01 sec)

mysql> insert into marks values('6','patil','640');


Query OK, 1 row affected (0.01 sec)

mysql> delimiter //
mysql> create procedure proc_result(in marks int,out class
-> char(20))
-> begin
-> if(marks<1500&&marks>990)
-> then
-> set class='Distincton';
-> end if;
-> if(marks<989&&marks>890)
-> then
-> set class='First Class';
-> end if;
-> if(marks<889&&marks>825)
-> then
-> set class='Higher Second Class';
-> end if;
-> if(marks<824&&marks>750)
-> then
-> set class='Second Class';
-> end if;
-> if(marks<749&&marks>650)
-> then
-> set class='Passed';
-> end if;
-> if(marks<649)
-> then
-> set class='Fail';
-> end if;
-> end;
-> //
Query OK, 0 rows affected, 5 warnings (0.01 sec)
mysql> create function final_result4(R1 int)
-> returns int
-> READS SQL DATA
-> DETERMINISTIC
-> begin
-> declare fmarks integer;
-> declare grade varchar(20);
-> declare stud_name varchar(20);
-> select marks.total_marks,marks.name into
-> fmarks,stud_name from marks where marks.roll_no=R1;
-> call proc_result(fmarks,@grade);
-> insert into result values(R1,stud_name,@grade);
-> return R1;
-> end;
-> //
Query OK, 0 rows affected (0.01 sec)

mysql> select final_result4(2);


-> //
+------------------+
| final_result4(2) |
+------------------+
| 2|
+------------------+
1 row in set (0.01 sec)

mysql> select final_result4(3);//


+------------------+
| final_result4(3) |
+------------------+
| 3|
+------------------+
1 row in set (0.01 sec)
mysql> select final_result4(4);//
+------------------+
| final_result4(4) |
+------------------+
| 4|
+------------------+
1 row in set (0.01 sec)

mysql> select final_result4(5);//


+------------------+
| final_result4(5) |
+------------------+
| 5|
+------------------+
1 row in set (0.00 sec)

mysql> select * from result;


-> //
+---------+--------+---------------------+
| roll_no | name | class |
+---------+--------+---------------------+
| 2 | piyush | First Class |
| 3 | hitesh | Higher Second Class |
| 4 | ashley | Second Class |
| 5 | partik | Passed |
+---------+--------+---------------------+
4 rows in set (0.00 sec)

You might also like