Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gbarreiro
Created August 20, 2020 15:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbarreiro/6cae236683279f6484136635a282cd8a to your computer and use it in GitHub Desktop.
Save gbarreiro/6cae236683279f6484136635a282cd8a to your computer and use it in GitHub Desktop.
MySQL cheatsheet: stored procedure
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