Home > Database > Mysql Tutorial > body text

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

Patricia Arquette
Release: 2024-10-26 15:46:30
Original
445 people have browsed it

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:

<code class="sql">READS SQL DATA</code>
Copy after login

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.

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

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.

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

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.

The above is the detailed content of How to Suppress \'Error 1329: No Data\' in Stored Procedures That Don\'t Return Data?. 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!