Using Variables

With variables, you can add logic to your procedures. Variables need to be declared and typed before use. It is good practice to differentiate the variables with a prefix (here 'v_') so the variables will not conflict with the column names and the report code will be easier to read.

drop procedure if exists sp_DBR_variables
$$
create procedure sp_DBR_variables()
begin

declare v_value integer;
declare v_date date;

set v_value = 1;
set v_date = now();

select v_value as 'Value', v_date as 'Date';

end
$$	
call sp_DBR_variables();
+-------+------------+
| Value | Date       |
+-------+------------+
|     1 | 2015-03-27 |
+-------+------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)