How does MySQL know that cursor traversal is over (a bunch of blogs are talking about junk)?

100 degrees TM is similar to this:

    declare done int default false;
    
    declare mycursor cursor for select * from ;
    declare continue HANDLER for not found set done = true;
    -- ,  not found ,  done  true.

but this time it brings a pit, because an ordinary select query, if not found, will also trigger the not found event, thus changing the value of the tag variable .

excuse me, doesn"t MySQL have a better strategy? If so, stored procedures are really hard to use!


select is not found, which means that the cursor has no content.


has just tried, but it will trigger as long as it is not found in select xxx into xxx. It is all common cases.
in that case, you can only write your own condition judgment.


recently used mysql cursors and found that using NOT FOUND to end cursors when other queries do not return results will trigger and cause early termination. Today, we found some inspiration in processing data. You can first query the total number of records of the cursor, and then use the number of records to determine the number of cycles.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bd75-2b315.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bd75-2b315.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?