A stored procedure is a set of SQL statements stored in a database. It could be just one SQL statement or many statements. With the help of this, you can reuse certain pieces of code. This can particularly be helpful when you are grouping business logic into a set of queries that will need to be run over and over again.
Creating and using stored procedures
Creating a stored procedure
Let's learn how to create a stored procedure. First, we'll go through the following syntax, which is used to create a stored procedure:
DELIMITER $$
CREATE PROCEDURE storedprocname()
BEGIN
your sql statments go here;
END $$
DELIMITER ;
In the previous code sample, we have the following:
- DELIMITER lets MySQL know that there may be lines...