Home  >  Article  >  Database  >  Why do I need to declare a NOT FOUND handler when using MySQL cursors?

Why do I need to declare a NOT FOUND handler when using MySQL cursors?

WBOY
WBOYforward
2023-09-09 16:33:07925browse

为什么在使用 MySQL 游标时需要声明 NOT FOUND 处理程序?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete