stored procedure with parameters mysql code example
Example 1: stored procedure with parameters mysql
DELIMITER $$
CREATE PROCEDURE get_clients_by_state
(
state CHAR(2)
)
BEGIN
SELECT
*
FROM
clients c
WHERE c.state = IFNULL(state, c.state);
END $$
DELIMITER ;
CALL get_client_by_state(NULL);
Example 2: stored procedure with parameters mysql
DELIMITER $$
CREATE PROCEDURE get_clients_by_state
(
state CHAR(2)
)
BEGIN
SELECT
*
FROM
clients c
WHERE c.state = state;
END $$
DELIMITER ;
CALL get_client_by_state('CA');
Example 3: stored procedure with parameters mysql
DELIMITER $$
CREATE PROCEDURE get_clients_by_state
(
state CHAR(2)
)
BEGIN
IF state IS NULL THEN
SET state = 'CA';
END IF;
SELECT
*
FROM
clients c
WHERE c.state = state;
END $$
DELIMITER ;
CALL get_client_by_state(NULL);
Example 4: mysql stored procedure parameters
DELIMITER
CREATE PROCEDURE GetOfficeByCountry(
IN countryName VARCHAR(255)
)
BEGIN
SELECT *
FROM offices
WHERE country = countryName;
END
DELIMITER ;Code language: SQL (Structured Query Language) (sql)