Professional Documents
Culture Documents
PR
PR
PR
Practical set-1
2. Write a procedure that will display ‘Hello world!’ as message1 and ‘’ This is my
first stored procedure‘’ as message2.
=> create procedure sp_two_message()
Begin
select 'Hello World' 1_Message , 'This is my first procedure' 2_Message;
end;
mysql> call sp_two_message;
-> &
+-------------+----------------------------+
| 1_Message | 2_Message |
+-------------+----------------------------+
| Hello World | This is my first procedure |
+-------------+----------------------------+
1 row in set (0.00 sec)
➢ Write a procedure that will display student name, city and contact number whose
student id is 5.
=> create procedure sp_stud_detail()
Begin
select sname,scity,contact from Student where sid=105;
End;&
mysql> call sp_stud_detail;&
+-------+-------+------------+
| sname | scity | contact |
+-------+-------+------------+
| Janki | Surat | 9909145893 |
+-------+-------+------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
➢ Write a procedure that will display all the details of students who belong to
‘Surat’ city.
=> create procedure sp_all()
Begin
select * from Student where scity='Surat';
End;&
mysql> call sp_all;&
+-----+---------+-------+------------+--------+-------------+
| sid | sname | scity | contact | gender | total_marks |
+-----+---------+-------+------------+--------+-------------+
| 101 | Rahul | Surat | 8000000000 | Male | 380 |
| 102 | Manthan | Surat | 9898187393 | Male | 430 |
| 105 | Janki | Surat | 9909145893 | Female | 400 |
+-----+---------+-------+------------+--------+-------------+
3 rows in set (0.00 sec)
➢ Write a procedure that will count total number of students whose marks is more
than 50.
=> create procedure sp_number()
Begin
select count(sname) from Student where total_marks>380;
End;&
mysql> call sp_number;&
+--------------+
| count(sname) |
+--------------+
| 2 |
+--------------+
1 row in set (0.00 sec)
➢ Write a procedure that will display highest and lowest marks of students along
with student name.
=> create procedure sp_max()
Begin
select max(total_marks),min(total_marks) from student;
End;&
mysql> call sp_max;&
+------------------+------------------+
| max(total_marks) | min(total_marks) |
+------------------+------------------+
| 430 | 350 |
+------------------+------------------+
1 row in set (0.00 sec)
➢ Write a procedure that will display student name whose marks is between 20 and
25.
=> create procedure sp_mid()
Begin
select sname from Student where total_marks between 380 and 440;
End;&
mysql> call sp_mid;&
+---------+
| sname |
+---------+
| Rahul |
| Manthan |
| Dharmil |
| Janki |
+---------+
4 rows in set (0.00 sec)
5.
create table emp_master
(
eid int primary key auto_increment,
ename varchar(20) not null,
gender varchar(10) not null,
department varchar(20) not null,
contact bigint not null,
salary int not null,
city varchar(20)not null
);&
➢ Insert 10 records.
=> create procedure sp_record()
Begin
insert into emp_master values
(101,'Manthan','Male','IT',9898187393,50000,'Surat'),
(102,'Janki','Female','HR',9909145893,45000,'Surat'),
(103,'Yug','Male','Marketing',9173063168,40000,'Bardoli'),
(104,'Nupur','Female','IT',9638527410,35000,'Bardoli'),
(105,'Vishmay','Male','HR',8000516155,30000,'Surat'),
(106,'Vishwa','Female','Marketing',7419638520,35000,'Surat'),
(107,'Preet','Male','IT',8520741963,40000,'Vapi'),
(108,'Henny','Female','HR',7894561230,45000,'Vapi'),
(109,'Rahul','Male','Marketing',9517538426,50000,'Valsad'),
(110,'Isha','Female','IT',7538426120,45000,'Valsad');
End;&
➢ Manager wants to know the employee who are coming from Surat city
=> create procedure surat()
begin
select ename from emp_master where city='Surat';
end;&
mysql> call surat;&
+---------+
| ename |
+---------+
| Manthan |
| Janki |
| Vishmay |
| Vishwa |
+---------+
4 rows in set (0.00 sec)