I am trying to write a simple cursor from inside my DBVisualizer tool against MySQL. Note that I am not writing a stored procedure. I am just writing a SQL Script which I plan to execute against the DB.
my script looks like
block1: BEGIN
declare my_id varchar(200);
declare foo cursor for select id from TableA where code in ('A', 'B');
open foo;
loop1: LOOP
fetch foo into my_id;
select my_id;
END LOOP loop1;
close foo;
END block1;
I found many many many examples on the web and everyone wrote the same code, but somehow this is not working for me. it says
3:39:42 [CLOSE - 0 rows, 0.010 secs] [Code: 1064, SQL State: 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 'close foo'
at line 1
My mysql version is
5.6.27-75.0-log
why is this not working for me? Once again, the above code was executed from inside DBVisualizer and this is not a stored procedure.