I have seen many pro*C programs, using a for loop to execute a set a statements "only once". For example,
for(i = 0; i < 1; i++)
{
EXEC SQL EXECUTE
DECLARE
/* some declarations here */
BEGIN
/* some PL/SQL code here */
END-EXEC;
}
Why is this for loop necessary ?
Just a wild guess: using such a loop might somehow simplify error handling when using WHENEVER DO BREAK or WHENEVER DO GOTO:
Consider the following code fragment:
for(i = 0; i < 1; i++)
{
EXEC SQL WHENEVER SQLERROR DO BREAK;
EXEC SQL UPDATE emp SET sal = sal * 10;
}
printf("%d",i);
If I'm not too wrong (don't have pro*C at hand right now), this would print 1 if the SQL query has completed without error. But 0 otherwise as we break before incrementing i.
Somewhat at the margin of that, there is a common idiom using an infinite for loop and a WHENEVER DO BREAK statement to fetch results:
EXEC SQL WHENEVER NOT FOUND DO break;
for (;;)
{
EXEC SQL FETCH...
}
EXEC SQL CLOSE my_cursor;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With