"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Suppress \"Error 1329: No Data\" in Stored Procedures That Don\'t Return Data?

How to Suppress \"Error 1329: No Data\" in Stored Procedures That Don\'t Return Data?

Published on 2024-11-02
Browse:187

How to Suppress \

Overcoming the "Error 1329: No Data" Dilemma

Many developers encounter the frustrating "Error 1329: No data - zero rows fetched, selected, or processed" when executing stored procedures. However, this error often occurs even when the procedure functions correctly, raising the question of how to suppress this unnecessary message.

One potential solution lies within the stored procedure itself. By default, stored procedures are expected to return a result set. However, if the procedure performs operations that do not yield any data (such as data manipulation or record updates), it will trigger the error message.

To resolve this, we can modify the stored procedure to explicitly indicate that it does not return any data. This can be achieved by adding the following line to the beginning of the procedure:

READS SQL DATA

This line informs the database that the procedure will only read from tables and will not return any rows.

Another approach involves handling the NOT FOUND exception within the procedure. When a cursor is used to fetch rows from a table, it may encounter a scenario where there are no more rows to fetch. This will cause the cursor to raise a NOT FOUND exception. By trapping this exception and setting a flag, we can avoid the error message.

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

By adding this line, we instruct the database to set the done flag to 1 when the cursor encounters the NOT FOUND exception. This flag can then be used to exit the cursor loop and complete the procedure without triggering the error message.

Finally, another workaround is to execute an additional dummy query that reads from a table and is successful. This will clear the warning on MySQL 5.5.13.

SELECT name INTO l_name FROM customer_tbl LIMIT 1;

By following these approaches, developers can suppress the "Error 1329" message for stored procedures that do not return any data, ensuring a smoother execution without unnecessary error prompts.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3