DECLAREvar_name[,...]type[DEFAULTvalue]
This statement is used to declare local variables. To provide
a default value for the variable, include a
DEFAULT clause. The value can be specified
as an expression; it need not be a constant. If the
DEFAULT clause is missing, the initial
value is NULL.
Local variables are treated like routine parameters with
respect to data type and overflow checking. See
Section 22.2.1, “CREATE PROCEDURE and CREATE
FUNCTION Syntax”.
The scope of a local variable is within the BEGIN ...
END block where it is declared. The variable can be
referred to in blocks nested within the declaring block,
except those blocks that declare a variable with the same
name.

User Comments
Simple example showing how to DECLARE variables:
DELIMITER //
CREATE PROCEDURE dec_examp()
BEGIN
DECLARE a CHAR(12) DEFAULT 'Hello';
DECLARE b CHAR(12);
DECLARE x, y INT;
--
SET b = ' World';
SELECT CONCAT(a, b);
--
SET x = 1;
SET y = 2;
SELECT x + y;
END;
//
DELIMITER ;
CALL dec_examp();
It is important to note that the DECLARE statements must appear at the beginning of the BEGIN...END block.
Add your own comment.