0

I tried to create a cursor in MySql using the following code. but I get the DECLARE is not valid ... error. why?

DECLARE CastCursor CURSOR
FOR
SELECT * FROM Customers
where cust_email IS NULL;
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Farshid
  • 17
  • 6
  • 3
    DECLARE can be used in compound code block only and must be placed at the same beginning of it, before any other statement. – Akina Jan 13 '23 at 21:01
  • 1
    'MySQL supports cursors inside stored programs.' - https://dev.mysql.com/doc/refman/8.0/en/cursors.html – P.Salmon Jan 14 '23 at 08:25
  • NB cursors should be a last resort where you have to iterate row by row and as such can be slow.. – P.Salmon Jan 14 '23 at 08:26

0 Answers0