Home >Database >Mysql Tutorial >Why do I need to declare a NOT FOUND handler when using MySQL cursors?
When using MySQL cursors, we must declare the NOT FOUND handler because it handles the case where the cursor cannot find any rows. It also handles when the cursor reaches the end of a row, because every time we call the FETCH statement, the cursor tries to try the next row in the result set. Following is the syntax for declaring NOT FOUND handler -
DECLARE CONTINUE HANDLER FOR NOT FOUND SET var_name = value;
Here var_name is the name of any variable and value is the value of that variable. For example, we can declare -
DECLARE CONTINUE HANDLER FOR NOT FOUND SET err = 1;as follows
The above is the detailed content of Why do I need to declare a NOT FOUND handler when using MySQL cursors?. For more information, please follow other related articles on the PHP Chinese website!