2010-07-08 28 views
1

我试图在嵌入式SQL中打印表的行。我有这个代码,其中发布是表和pubid是属性。我试过这个:如何摆脱使用但未定义的标签

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; 

编译器给了我这个错误:error:label'close_c1'used used but defined。 我该如何解决这个问题?

+0

这是真正关心你的嵌入式SQL处理一个问题 - 您使用的是哪一个? – 2010-07-08 19:16:38

+0

我正在使用DB2与C++ – Dave 2010-07-08 19:55:17

+0

我怀疑你的WHENEVER语句不是,当处理发射C++'goto'语句。现在,嵌入式SQL的使用非常少见,所以您最好在DB2特定的站点上询问。 – 2010-07-08 21:34:06

回答

1

只是猜测... 把WHENEVER行首先放入你的嵌入式sql序列。

从“SQL参考卷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.