Md shahadat Hossain
Md shahadat Hossain

Reputation: 11

Stored Procedure with dynamic varriable

I am learning MySQL from YouTube. I am at beginner level . I want to know why we use @F_emps . here

to create new table

create table employees_detailss (
    Emp_id int primary key, 
    Emp_name varcharacter (28), 
    Age int, 
    Gender character (10), 
    Department varcharacter (25), 
    City character (22), 
    salary float
);

to know how the table elements

describe employees_details ; 

to insert values

Insert into employees_detailss
values 
( 5524, "Jimmie Clayton", 44,"M", "Marketing", "Berlin", 35000),
(2174,  "Clyde Turner", 34, "F" , "Finance", "Paris",   23000),
(4141,  "Carol Hubbard" , 37, "M",  "IT","Rome", 45000),
(6182,  " Dennis Flores" , 45, "M",  "Supply chain", " Venis", 28000),  
(5324,  "Stewart Bowers", 47 , "F" ,  "IT", " London" ,  50000),    
(7446,  "Nichole Bush", 27, "M" ,"Marketing", "Lisbon", 20000),
(965,   "Anne Brady",   32, "F",  "Finance", "Berlin",28000),   
(6177,  "Kristina Riley",36,"F", "Supply chain", "Milan", 34000),   
(4855,  "Evan Martin",  34,"M",  "Finance", "Soest",29000),
(5899,  "Josephine Mason", 47, "M",  "IT", "Dresden", 44000),
(1994,  "Manuel Houston",33,"F", "Marketing", "Munich", 42000),
(387,   "Robyn Fernandez", 27, "M",  "Finance", "Postdam",40000),
(2125,  "Bessie Richardson", 35, "F",  "IT", "Hamburg", 34000),
(8180,  "Christie Henderson", 33, "F", "Marketing", "Cottbus", 44000);
select * from employees_detailss ;
delimiter //
create Procedure Sp_CountEmployeesss ( out Total_emps int )
begin 
select count(Emp_name) into Total_emps from employees_detailss
where Gender = "F";
end //
delimiter ;

call Sp_CountEmployeesss(@F_emps);
select @F_emps as Female_Emps;

Upvotes: 0

Views: 31

Answers (1)

Skatox
Skatox

Reputation: 4284

When you do the call:

call Sp_CountEmployeesss(@F_emps);
select @F_emps as Female_Emps;

What it means is that you pass a variable to Sp_CountEmployeesss to store the result(s). Then after the call's line, the data is saved in @F_emps so you'll do a select to query the result and see the calculated data.

Upvotes: 1

Related Questions