For a loop spanning PL / SQL blocks in pro * C

I've seen many pro * C programs using a for loop to execute a set of statements "just 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 necessary for the loop?

+3


source to share


1 answer


Just a wild guess: using a loop like this could somehow simplify error handling when using WHENEVER DO BREAK

either WHENEVER DO GOTO

:

Consider the following piece of code:

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 mistaken (I don't have a pro * C right now) this will print 1 if the SQL query completed without errors. But 0 otherwise when broken before incrementing i

.




To some extent on this basis, there is a common idiom using an infinite for loop and a statement WHENEVER DO BREAK

to get results:

EXEC SQL WHENEVER NOT FOUND DO break;
for (;;)
{
    EXEC SQL FETCH...
}
EXEC SQL CLOSE my_cursor; 

      

+1


source







All Articles