Home >Database >Mysql Tutorial >**How to Resolve \'Error 1329: No Data\' in Stored Procedures When No Result is Expected?**
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
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>
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>
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>
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!