Stored procedures
Suppose you need to execute a series of statements in MySQL, instead of sending all SQL statements every time, you can encapsulate all the statements in a single program and call it whenever required. A stored procedure is a set of SQL statements for which no return value is needed.
Apart from SQL statements, you can make use of variables to store results and do programmatical stuff inside a stored procedure. For example, you can write IF
, CASE
clauses, logical operations, and WHILE
loops.
- Stored functions and procedures are also referred to as stored routines.
- For creating a stored procedure, you should have the
CREATE ROUTINE
privilege. - Stored functions will have a return value.
- Stored procedures do not have a return value.
- All the code is written inside the
BEGIN and END
block. - Stored functions can be called directly in a
SELECT
statement. - Stored procedures can be called using the
CALL
statement. - Since the statements inside stored routines should end with a delimiter (
;
), you...