In this post we will learn how to create a stored procedure with output parameter and how can we execute this procedure. For this, we will write a procedure that gets two parameters and returns their sum.
The stored procedure code is below.
1 2 3 4 5 6 7 8 9 10 |
DELIMITER $$ CREATE PROCEDURE `SP_Sum`( IN `n1` INT, IN `n2` INT, OUT `result` INT ) BEGIN Set result = n1 + n2; END$$ DELIMITER ; |
After running this procedure we must get succesful message than we can use this procedure with the codes below.
1 2 3 |
Call SP_Sum(2,3,@sayi); SELECT @sayi; #result-->5 |
Example 2
1 2 3 |
Call SP_Sum(12,7,@sayi); SELECT @sayi; #result-->20 |