Bug #48233 Unable to declare variables
Submitted: 22 Oct 2009 14:34 Modified: 22 Oct 2009 15:01
Reporter: A S Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Options Severity:S3 (Non-critical)
Version:5.1.37 OS:Linux (Fedora 11 kernel 2.6.30.8-64.fc11.i686)
Assigned to: CPU Architecture:Any
Tags: error 1064, variables

[22 Oct 2009 14:34] A S
Description:
declare i int default 0;
If I execute this statement, I get the following message. Even the example given for variable in mysql documentation isn't working. 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare i int default 0' at line 1

How to repeat:
Use the following query

declare i int default 0;
[22 Oct 2009 14:50] Valeriy Kravchuk
DECLARE can be used only in BEGIN ... END blocks. Please, check the manual:

http://dev.mysql.com/doc/refman/5.1/en/declare-local-variable.html
http://dev.mysql.com/doc/refman/5.1/en/local-variable-scope.html