What happens if updating cursor did not fetch any records
If the cursor query would not return any rows at all, the snippet would still work, but to me, a is like a marker saying: "Ho there, here's some work that needs to be done, and maybe we'll have to repeat it a couple of times".Not surprisingly, I really almost never have the need to write any loop like this.Generally, people favour structured loops over unstructured ones.The syntactic design of the structured loop constructs makes it easy to see where the repetition terminates and what condition controls termination.I mean, we have both the checking essentially an inverse condition.And it's not just something that has to do with this particular snippet; it really has to do with this type of cursor loop in general.The values that we would be inserting are in fact the same values that were inserted during the first loop cycle, because the wich will terminate the loop. The second has to do with efficiency, and is as far as I can see not really open to any debate.(But hey, feel free to do post a comment; as some advertising bots seem to have discovered, comments on this blog can be made anonymously).
When the cursor is opened, the cursor's internal record pointer will be positioned right before that first and only record.
I feel quite a bit more strong about another thing.
I think that it is really not very good to have to different checks that test the same condition.
In my previous post, I illustrated construct there in both examples. I didn't make it up myself, I took it from the Cursors section in the My SQL Reference manual. Superficially all this seems to make sense, but I'll try and convince you that this is actually all wrong. Let's say that I think that this is not as good as it could be.
In fact, I usually handle cursors in My SPL using the unstructured loop construct. Take a look at the body of the loop; I mean the statements inbetween the ?