MySQL Stored Procedure Variables
In MySQL, stored procedures support two types of variables for use within the procedure: Local Variables and User-Defined Variables. These variables enable you to store intermediate results, pass values between queries, and control procedure logic.
Types of Variables in MySQL Stored Procedures
Local Variables:
- Declared within a stored procedure using the
DECLARE
statement. - The scope is limited to the stored procedure in which they are declared.
- Automatically destroyed when the procedure ends.
- Cannot use
@
in their names.
- Declared within a stored procedure using the
User-Defined Variables:
- Prefixed with
@
and accessible globally within the session. - Persist for the duration of the session unless explicitly reset.
- Do not require a declaration.
- Prefixed with