How to solve the problem that return can not be used in mysql stored procedures
This article mainly explains "how to solve the problem that return can not be used in mysql stored procedures". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the problem that return cannot be used in mysql stored procedures.
Everyone knows that stored procedures cannot use return statements, and only stored functions have this function. So, is there an alternative to return?
No!
There are no keywords like exit and quit!
What shall I do?
Use the less functional leave keyword, which mimics the behavior of return.
Give me an example:
SET FOREIGN_KEY_CHECKS=0
-- Procedure structure for sp_test_return
DROP PROCEDURE IF EXISTS `sp_test_ roomn`
DELIMITER
CREATE PROCEDURE `sp_test_ roomn` (In num integer)
Label_pro:begin www.2cto.com
If num > 3 then
Leave label_pro
Else
Select num as exeuted
End if
End
DELIMITER
In this example, the entry of the entire stored procedure is marked, and when you encounter a need to exit the stored procedure, just leave + this tag.
At this point, I believe you have a deeper understanding of "how to solve the problem that return cannot be used in mysql stored procedures". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!