create stored procedure mysql parameters code example
Example 1: stored procedure with parameters mysql
-- Stored Procedure with parameters with default
-- this examble return all clients in all states if parameter is NULL
DELIMITER $$
CREATE PROCEDURE get_clients_by_state
(
state CHAR(2)
)
BEGIN
SELECT
*
FROM
clients c
WHERE c.state = IFNULL(state, c.state);
END $$
DELIMITER ;
-- Once you save the stored procedure, you can invoke it by using the CALL statement:
CALL get_client_by_state(NULL);
Example 2: create stored procedure mysql
DELIMITER $$
CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT * FROM products;
END $$
DELIMITER ;
-- Once you save the stored procedure, you can invoke it by using the CALL statement:
CALL GetAllProducts();