MySQL Tutorials - Herong's Tutorial Examples - Version 4.20, by Dr. Herong Yang
Local Variables in Stored Procedures
This section describes local variables used in stored procedures. DECLARE statements are used to declare local variables.
A stored procedure can have local variables.
To define a local variable, you can use the DECLARE statement:
DECLARE variable data_type [DEFAULT value];
To assign a new value to a variable, you can use the SET statement:
SET variable = expression;
The SELECT statement can also be used to assign values to variables:
SELECT expression, expression, ... INTO variable, variable, ... [FROM clause];
Once a variable is defined, it can be used in any expressions in any statements.
Last update: 2015.
Table of Contents
MySQL Introduction and Installation
Introduction of MySQL Programs
Perl Programs and MySQL Servers
PHP Programs and MySQL Servers
Java Programs and MySQL Servers
Character Strings and Bit Strings
Table Column Types for Different Types of Values
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Transaction Management and Isolation Levels
Defining and Calling Stored Procedures
►Variables, Loops and Cursors Used in Stored Procedures
►Local Variables in Stored Procedures
Execution Flow Control Statements
ITERATE and LEAVE - Statements to Break Loops