Cursor Loops & Handlers
Learn Cursor Loops & Handlers (Cursors, MySQL) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Introduction MySQL has no "has next" test. When FETCH runs past the last row it raises SQLSTATE 02000 (NOT FOUND) . You catch that with a DECLARE ... HANDLER FOR NOT FOUND that sets a flag, and the loop tests the flag right after the FETCH.