1-- MySQL
2
3-- example
4DELIMITER $$ -- Changes delimiter to $$ so can use ; within the procedure
5CREATE PROCEDURE select_employees()
6BEGIN
7 select *
8 from employees
9 limit 1000; -- Use the ; symbol within the procedure
10END$$
11DELIMITER ; -- Resets the delimiter
12
13/* syntax:
14DELIMITER $$ -- Changes delimiter to $$ so can use ; within the procedure
15CREATE PROCEDURE <Your-procedure-name>(<argument1><argument2>...<argumentN>)
16BEGIN
17 <Code-that-stored-procedure-executes>; -- Use the ; symbol within the procedure
18END$$
19DELIMITER ; -- Resets the delimiter
20*/
1DELIMITER $$
2
3CREATE PROCEDURE GetCustomers()
4BEGIN
5 SELECT
6 customerName,
7 city,
8 state,
9 postalCode,
10 country
11 FROM
12 customers
13 ORDER BY customerName;
14END $$
15
16DELIMITER ;
17
18
19-- Once you save the stored procedure, you can invoke it by using the CALL statement:
20
21CALL GetCustomers();
22
1DELIMITER $$
2
3CREATE PROCEDURE GetAllProducts()
4BEGIN
5 SELECT * FROM products;
6END $$
7
8DELIMITER ;
9
10
11-- Once you save the stored procedure, you can invoke it by using the CALL statement:
12
13CALL GetAllProducts();
14