1

I'm trying to print the rows of a table in embedded sql. I have this code where publication is the table and pubid is the attribute. I tried this:

    EXEC SQL DECLARE C1 CURSOR FOR SELECT pubid FROM publication;
    EXEC SQL OPEN C1;
    EXEC SQL WHENEVER NOT FOUND GOTO close_c1;
    for(;;) {
        EXEC SQL FETCH C1 INTO :pubid;
        cout<<pubid<<endl;
    }
    close_c1:
    EXEC SQL CLOSE C1;

The compiler gives me this error: error: label 'close_c1' used but not defined. How do I fix this?

Dave
  • 81
  • 6
  • This is really a question about your embedded SQL processor - which one are you using? –  Jul 08 '10 at 19:16
  • I suspect that your WHENEVER statement is not, when processed emitting a C++ `goto` statement. Use of embedded SQL is pretty rare these days, so you may be better off asking on a DB2-specific site. –  Jul 08 '10 at 21:34

1 Answers1

1

Just guessing... Put the WHENEVER line first in your embedded sql sequence.

From "SQL Reference Volume 2":

WHENEVER
.....
Note:
.....
Every executable SQL statement in a program is within the scope of one implicit or >explicit WHENEVER statement of each type. The scope of a WHENEVER statement is related to the listing sequence of the statements in >the program, not their execution sequence.

Putte
  • 74
  • 6