The concept of mysql stored procedure:
It is stored in the database and can perform specific work (query and update) A set of program segments of SQL code.
The concept of mysql function:
A function is an SQL statement that completes a specific function. Functions are divided into built-in functions and user-defined functions (user-defined function UDF)
The difference between MySQL stored procedures and functions
Stored procedures are a set of sql statements to complete specific functions. They are compiled, created and saved in the database. The idea is code encapsulation and reuse at the database SQL language level.
Note: in refers to input parameters, out refers to output parameters
Create a custom function
Syntax format : create function name (parameter type, parameter type...) returns type return expression value;
Note: 1. There can be no or multiple parameters.
2. There must be a return value, and there is only one.
3. If there is a SQL statement, it should be placed in the middle of begin...end.
4. If you don’t add determministic, an error will be reported (I don’t know how to solve it)
begin...end compound statement
usually appears in Stored procedures, functions and triggers can contain one or more statements, each statement separated by;.
Related learning recommendations: mysql tutorial
The above is the detailed content of Analyze MySQL stored procedures and common function codes. For more information, please follow other related articles on the PHP Chinese website!