Home > Database > Mysql Tutorial > body text

How to Resolve \'Error 1329: No Data Fetched, Selected, or Processed\' in MySQL Stored Procedures?

Susan Sarandon
Release: 2024-10-25 19:11:02
Original
159 people have browsed it

How to Resolve

How to Eliminate "Error 1329: No Data Fetched, Selected, or Processed"

When executing stored procedures that do not return values, users may encounter "Error 1329: No data - zero rows fetched, selected, or processed." To address this issue, follow these steps:

Consider the following stored procedure:

CREATE PROCEDURE `testing_proc`()  
    READS SQL DATA  
BEGIN  
    DECLARE done INT DEFAULT 0;
    DECLARE l_name VARCHAR(20);
    DECLARE my_cur CURSOR FOR
        SELECT name FROM customer_tbl;
    OPEN my_cur;
        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;
    CLOSE my_cur;
END
Copy after login

The error stems from MySQL's behavior of displaying a warning even when it has been handled. To prevent this, include the following line at the end of the procedure:

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
Copy after login

Alternatively, add a "dummy" statement that involves a table and executes successfully after the loop, for example:

SELECT name INTO l_name FROM customer_tbl LIMIT 1;
Copy after login

This will clear the warning due to a bug/strange behavior in MySQL (referenced in http://dev.mysql.com/doc/refman/5.5/en/show-warnings.html).

The above is the detailed content of How to Resolve \'Error 1329: No Data Fetched, Selected, or Processed\' in MySQL Stored Procedures?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!