can we declare cursor outside procedures in mysql

Viewed 1409

I am not able to declare cursor. what is significance of cursor in mysql

declare c1 cursor for select name from record

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 c1 cursor for select name from record' at line 1

2 Answers

Cursors are used inside a stored programs to go through a result set (i.e. they are not available outside the stored programs).

Do remember that SQL is set based, so try to think first if the task you are trying to do can be resolved using normal (select/insert/update/delete). Serializing the queries via cursors should be a last solution.

Related