Why is it necessary to declare NOT FOUND handler while using MySQL cursor?


We must have to declare NOT FOUND handler while working with MySQL cursor because it handles the situation when cursor could not find any row. It also handles the situation when the cursor reaches the end of the row because every time we call FETCH statement the cursor finds to attempt the next row in the result set. Following is the syntax to declare NOT FOUND handler −

DECLARE CONTINUE HANDLER FOR NOT FOUND SET var_name = value;

Here var_name is the name of any variable and value would be the value of that variable. For example, we can declare it as follows −

DECLARE CONTINUE HANDLER FOR NOT FOUND SET err = 1;

Updated on: 22-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements