A stored procedure in MariaDB is a set of SQL statements that can be stored in the server. Once this has been done, the client doesn’t need to keep reissuing the individual statements but can refer to the stored procedure instead.
Here is a basic example of a stored procedure:
```
DELIMITER //
CREATE PROCEDURE MyFirstProcedure()
BEGIN
SELECT * FROM Products;
END //
DELIMITER ;
```
In this example,
- `DELIMITER //` changes the standard delimiter (semicolon) in MySQL statement to `//`.
- `CREATE PROCEDURE MyFirstProcedure()` is beginning of the stored procedure. `MyFirstProcedure` is the name of the procedure. The parentheses `()` hold input parameters, it is empty in this case as we are not using any input parameter.
- `BEGIN` and `END` form the body of stored procedure. Between these two, you can write multiple SQL statements. Here, we are using a simple SQL select statement `SELECT * FROM Products;` which selects all data from the `Products` table.
- The final `DELIMITER ;` changes the delimiter back to the regular semicolon which is used at the end of each SQL statement.
Now, let’s call this stored procedure:
```
CALL MyFirstProcedure();
```
This `CALL` statement is used to run the stored procedure.
Make sure change `MyFirstProcedure`, `Products` to ones that exist in your database.