User-defined variables in MySQL
MySQL recognizes different types of variables. The first type is user-defined variables, identified by an @ symbol used as a prefix. In MySQL, user-defined variables can be accessed without first declaring or initializing them. If you do so, a NULL value is assigned to the variable when it is initialized.
Declaring local variables in MySQL
Local variables do not need the @ prefix in their names, but they must be declared before they can be used. To declare a local variable, you can use the DECLARE statement or use it as a parameter within a STORED PROCEDURE statement.
When declaring a local variable, you can optionally assign a default value to it. If you assign no default value, the variable is initialized with a NULL value.
Each variable lives within a scope, delimited by the BEGIN ... END block containing its declaration.
For Example declare :
DECLARE variable TYPE [DEFAULF VALUE]
DECLARE a INT;
DECLARE a INT DEFAULT 0;
DECLARE a VARCHAR(12);
DECLARE a VARCHAR(12) DEFAULT '';
DECLARE a CHAR;
DECLARE a CHAR DEFAULT '';
DECLARE a FLOAT;
DECLARE a FLOAT DEFAULT 0.0;
DECLARE a BOOLEAN;
DECLARE a BOOLEAN DEFAULT TRUE;
Other Example :
DELIMITER $$
CREATE PROCEDURE GetUpdatedPrices(itemcount INT)
BEGIN
DECLARE factor DECIMAL(5, 2);
SET factor:=3.45;
SELECT PartNo, Description, itemcount * factor * ListPrice FROM Catalogue;
END
$$
DELIMITER ;
You must define the type and optionally the value it contains, for example if it is a counter it is logical that the value of the default variable is 0.
And the rest as you have it.