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

MySQLMySQLi Database

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;
raja
Published on 21-Feb-2018 11:19:11
Advertisements