-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPL_SQL stored procedure and function.txt
50 lines (50 loc) · 1.67 KB
/
PL_SQL stored procedure and function.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
create database Score;
use Score;
create table stud_marks(name varchar(20),total_marks int(5));
create table Result(roll_no int(3) primary key,name varchar(20),class varchar(20));
insert into stud_marks values('Suresh',995);
insert into stud_marks values('Harish',865);
insert into stud_marks values('Samart',920);
insert into stud_marks values('Mohan',1000);
insert into stud_marks values('Soham',745);
select * from stud_marks;
insert into Result(roll_no,Name) values(1,'Suresh');
insert into Result(roll_no,Name) values(2,'Harish');
insert into Result(roll_no,Name) values(3,'Samart');
insert into Result(roll_no,Name) values(4,'Mohan');
insert into Result(roll_no,Name) values(5,'Soham');
select * from Result;
delimiter //
create procedure proc_Grade(in r int(2),out grade char(25))
begin
declare m int(4);
select total_marks into m from stud_marks where name=(select name from Result where roll_no=r);
if m>=990 and m<=1500 then
select 'Distinction' into grade;
update Result set Class='Distinction' where Roll_no=r;
elseif m>=900 and m<=989 then
select 'FirstClass' into grade;
update Result set Class='FirstClass' where Roll_no=r;
elseif m>=825 and m<=899 then
select 'SecondClass' into grade;
update Result set Class='SecondClass' where Roll_no=r;
else
select '--' into grade;
update Result set Class='--' where Roll_no=r;
end if;
end //
delimiter //
create function func_Grade(r int(2))
returns varchar(25)
deterministic
begin
declare grade varchar(25);
call proc_Grade(r,grade);
return grade;
end //
select func_Grade(1); //
select func_Grade(2); //
select func_Grade(3); //
select func_Grade(4); //
select func_Grade(5); //
select * from Result; //