I have a stored procedure created to calculate the standard deviation by hand by going through each row in Employees Table in DB2 Sample Database -
However, the procedure is stuck in an infinite loop. I am not sure as to why it is stuck as i expected the SQLSTATE to not be '00000' after reading last row on table and hoped to exit. What is the problem? How do I debug? How do I fix it?
The
SQLSTATEvariable resets after each statement exceptGET DIAGNOSTICS. This is why everySQLSTATEcheck must followFETCHimmediately. There is another technique of such a loop processing based on exception handler forNOT FOUNDcondition + a flag variable to set there.Below is one of possible solutions.