-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14-Stored-procedures.sql
More file actions
38 lines (30 loc) · 1.07 KB
/
14-Stored-procedures.sql
File metadata and controls
38 lines (30 loc) · 1.07 KB
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
-- Stored Procedures (reusable piece of code, which will execute everytime you 'call' the stored procedure)
create procedure large_salaries()
select * from employee_salary where salary>=50000;
call large_salaries();
create procedure large_salaries2()
select * from employee_salary where salary>=50000;
select * from employee_salary where salary>=10000; -- this query did not become part of the procedure
call large_salaries2();
DELIMITER $$ -- (changing the delimiter from ; to $$, now $$ will tell when something ends which was previously done by ;) (we can also use // or some other signs)
create procedure large_salaries3()
begin
select *
from employee_salary
where salary >= 50000;
select *
from employee_salary
where salary >= 10000; -- now both the queries are inside the procedure
end $$
DELIMITER ; -- changing the delimiter back to ;
call large_salaries3();
-- Parameters
DELIMITER $$
create procedure large_salaries4(emp_id int)
begin
select *
from employee_salary
where employee_id = emp_id;
end $$
DELIMITER ;
call large_salaries4(1);