SQL: Stored Routines

DELIMITER $$CREATE PROCEDURE procedure_name (possible parameters)
BEGIN
SQL Code
END$$
DELIMITER ;
DELIMITER $$CREATE PROCEDURE number_clients_state (IN state_v VARCHAR(20))
BEGIN
SELECT COUNT(*)
FROM clients
WHERE state = state_v;
END$$
DELIMITER ;
CALL number_clients_state('New York');
DELIMITER $$CREATE FUNCTION function_name (parameter_name data_type) RETURN data_type
(NOT) DETERMINISTIC
BEGIN
DECLARE variable_name data_type
SQL CODE
RETURN variable_name
END$$
DELIMITER ;
DELIMITER $$CREATE FUNCTION convert_sqft_sqmet (area DECIMAL(10,2)) RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE square_meters DECIMAL(10, 2);
SELECT area * 0.0929 INTO square_meters;
RETURN square_meters;
END$$
DELIMITER ;

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store