Created
August 20, 2020 15:12
-
-
Save gbarreiro/6cae236683279f6484136635a282cd8a to your computer and use it in GitHub Desktop.
MySQL cheatsheet: stored procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER // -- we need to change it, in order to be able of writing ; in the instructions | |
CREATE PROCEDURE get_age(IN user_id INT, OUT user_age INT) -- the procedure has one parameter and returns one variable | |
BEGIN | |
SELECT age INTO user_age FROM Students WHERE id = user_id; | |
-- more instructions... -- | |
END // | |
DELIMITER ; -- don't forget to restore the original delimiter ! | |
CALL get_age(12, @age); -- call the procedure, send a parameter and store the result into the session variable age | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment