Bug #27823 DECLARE CURSOR after SET statement throws spurious error
Submitted: 14 Apr 2007 15:55 Modified: 15 Apr 2007 5:18
Reporter: Peter Brawley (Basic Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.0.37 OS:Windows
Assigned to: CPU Architecture:Any
Tags: qc

[14 Apr 2007 15:55] Peter Brawley
Description:
drop table if exists t;
create table t(id int);

drop procedure if exists showerr;
delimiter |
create procedure showerr()
begin
  declare pack char(255);
  set pack = '';
  declare cur1 cursor for select id from t;
end;
|
delimiter ;

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 cur1 cursor for select id from t; end' at line 5

How to repeat:
As above
[15 Apr 2007 5:18] Giuseppe Maxia
This is expected behavior. 

http://dev.mysql.com/doc/refman/5.0/en/declare.html
"DECLARE is allowed only inside a BEGIN ... END compound statement and must be at its start, before any other statements."