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

Practical No 5.1

Uploaded by

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

Practical No 5.1

Uploaded by

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

Practical No 5

mysql> create database student; Query

OK, 1 row affected (0.00 sec)

mysql> use student;

Database changed

mysql> create table student(roll_no int primary key,name varchar(20),total_marks int);

Query OK, 0 rows affected (0.00 sec)

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

Query OK, 0 rows affected (0.00 sec)

mysql> insert into student values(1,'Shizuka',1400);

Query OK, 1 row affected (0.00 sec)

mysql> insert into student values(2,'Olly',1000);

Query OK, 1 row affected (0.00 sec)

mysql> insert into student values(3,'Nobita',1450);

Query OK, 1 row affected (0.00 sec)

mysql> insert into student values(4,'Oggy',909);

Query OK, 1 row affected (0.00 sec)

mysql> insert into student values(5,'Doraemon',890);

Query OK, 1 row affected (0.00 sec)

mysql> insert into student values(6,'Jack',980);

Query OK, 1 row affected (0.00 sec)

mysql> delimiter //

mysql> create procedure proc_result(in marks int,out class char(20))


-> begin
-> if(marks<=1500&&marks>=990)
-> then
-> set class='Distinction';
-> end if;
-> if(marks<989&&marks>900)
-> then
-> set class='First Class';
-> end if;
-> if(marks<899&&marks>825)
-> then
-> set class='Second Class';
-> end if;
-> end;
-> //
Query OK, 0 rows affected (0.00 sec)

mysql> create function final_result1(R1 int)

-> returns int


-> begin
-> declare fmarks integer;
-> declare grade varchar(20);
-> declare stud_name varchar(20);
-> select student.total_marks,student.name into fmarks,stud_name from student where student.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.00 sec)

mysql> select final_result1(1);

-> //
+ +
| final_result1(1) |
+ +
| 1|
+ +
1 row in set (0.00 sec)
mysql> select final_result1(2);
-> //
+ +
| final_result1(2) |
+ +
| 2|
+ +
1 row in set (0.00 sec)
mysql> select final_result1(3);
-> //
+ +
| final_result1(3) |
+ +
| 3|
+ +
1 row in set (0.00 sec)
mysql> select final_result1(4);
-> //
+ +
| final_result1(4) |
+ +
| 4|
+ +
1 row in set (0.00 sec)
mysql> select final_result1(5);
-> //
+ +|
final_result1(5) |
+ +
| 5|
+ +
1 row in set (0.00 sec)
mysql> select final_result1(6);
-> //
+ +
| final_result1(6) |
+ +
| 6|
+ +
1 row in set (0.01 sec)
mysql> select * from student;
-> //
+ + + +
| roll_no | name | total_marks |
+ + + +
| 1 | Shizuka | 1400 |

| 2 | Olly | 1000 |

| 3 | Nobita | 1450 |

| 4 | Oggy | 909 |

| 5 | Doraemon 890 |
|
| 6 | Jack | 980 |
+ + + +

6 rows in set (0.00 sec)

mysql> select * from result;

-> //

+ + + +
| roll_no | name | class |
+ + + +
| 1 | Shizuka | Distinction |
| 2 | Olly | Distinction |
| 3 | Nobita | Distinction |
| 4 | Oggy | First Class |
| 5 | Doraemon | Second Class |
| 6 | Jack | First Class |
+ + + +

6 rows in set (0.00 sec)

You might also like