This MariaDB tutorial explains how to create and drop procedures in MariaDB with syntax and examples.
In MariaDB, a procedure is a stored program that you can pass parameters into. It does not return a value like a function does.
Just as you can create procedures in other languages, you can create your own procedures in MariaDB. Let's take a closer look.
The syntax to create a procedure in MariaDB is:
Optional. If not specified, the definer is the user that created the procedure. If you wish to specify a different definer, you must include the DEFINER clause where user_name is the definer for the procedure.
The name to assign to this procedure in MariaDB.
One or more parameters passed into the procedure. When creating a procedure, there are three types of parameters that can be declared:
It is in the syntax for portability but will have no impact on the function.
It means that the function will always return one result given a set of input parameters.
It means that the function may return a different result given a set of input parameters. The result may be affected by table data, random numbers or server variables.
It is the default. It is an informative clause that tells MariaDB that the function contains SQL, but the database does not verify that this is true.
It is an informative clause that is not used and will have no impact on the function.
It is an informative clause that tells MariaDB that the function will read data using SELECT statements but does not modify any data.
It is an informative clause that tells MariaDB that the function will modify SQL data using INSERT, UPDATE, DELETE, or other DDL statements.
The place in the procedure where you declare local variables.
The place in the procedure where you enter the code for the procedure.
Let's look at an example that shows how to create a procedure in MariaDB:
You could then reference your new procedure as follows:
Once you have created your procedure in MariaDB, you might find that you need to remove it from the database.
The syntax to a drop a procedure in MariaDB is:
The name of the procedure that you wish to drop.
Let's look at an example of how to drop a procedure in MariaDB.
For example:
This example would drop the procedure called CalcValue.