This MariaDB tutorial explains how to use the RETURN statement in MariaDB with syntax and examples.
In MariaDB, the RETURN statement is used when you are want to exit a function and return the result of the function. It can also be used to terminate a LOOP and then exit with the result.
The syntax for the RETURN statement in MariaDB is:
The result that is to be returned by the function.
Let's look at an example that shows how to use the RETURN statement in MariaDB:
In this RETURN example, the function called CalcValue will exit when it encounters the RETURN statement and return the value stored in the total_value variable as the result of the function.
You could have also used the RETURN statement to terminate the loop called label1. For example:
In this RETURN example, we use the RETURN statement twice.
The first RETURN statement is within the LOOP statement and when encountered will exit the LOOP, exit the function, and return the value stored in the variable called total_value.
The second RETURN statement is used at the end of the function to exit the function and return the value stored in the starting_value variable.
In this example, we have used the RETURN statement to create 2 exit points in the function.