Home > Database > Mysql Tutorial > body text

**How to Resolve \'Error 1329: No Data\' in Stored Procedures When No Result is Expected?**

Mary-Kate Olsen
Release: 2024-10-28 20:30:30
Original
835 people have browsed it

**How to Resolve

How to Handle "Error 1329: No Data" with Stored Procedures

Problem:

You have a stored procedure that does not need to return any values. It executes successfully, but it outputs an error message after completion:

Error: No data - zero rows fetched, selected, or processed
Copy after login

Solution:

The error message appears because the stored procedure does not explicitly handle the case where no data is returned by any of its operations. To resolve this, you can include a DECLARE CONTINUE HANDLER statement to ignore the NOT FOUND error:

<code class="sql">DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;</code>
Copy after login

Explanation:

The DECLARE CONTINUE HANDLER statement tells MySQL to ignore the NOT FOUND error and continue executing the stored procedure. In your specific case, this statement should be added after the loop that iterates over the rows in the customer_tbl table:

<code class="sql">my_cur_loop:
LOOP
FETCH my_cur INTO l_name;
IF done = 1 THEN
LEAVE my_cur_loop;
END IF;
INSERT INTO names_tbl VALUES(l_name);
END LOOP my_cur_loop;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;</code>
Copy after login

Additional Note:

For MySQL version 5.5.13 and above, you can also add a "dummy" statement to the end of the stored procedure to clear the warning:

<code class="sql">SELECT name INTO l_name FROM customer_tbl LIMIT 1;</code>
Copy after login

This statement is successful and does not involve any data, effectively clearing the warning message.

The above is the detailed content of **How to Resolve \'Error 1329: No Data\' in Stored Procedures When No Result is Expected?**. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template