Get the App
SLTechnology News&Howtos  ›  Database  › 

How to solve the problem that return can not be used in mysql stored procedures

Shulou Source: shulou.com Published: 2022-05-31 18:00:17 09月22日 Update

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!

Tags: Storage procedure key keyword problem content function tag learning utility deeper example entry interest function only practicality practicality how to do simple operation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno Docker MariaDB macOS