日期:2014-05-16 浏览次数:20857 次
下面的代码是双层游标循环:
?
EXEC SQL PREPARE stat_ifinfo FROM :ifinfoSQL; EXEC SQL DECLARE cur_ifinfo CURSOR FOR stat_ifinfo; EXEC SQL OPEN cur_ifinfo USING :tpStr, :passTypeStr; /* 接口定义表的游标声明、定义与打开 */ EXEC SQL PREPARE stat_msgno FROM :msgnoSQL; EXEC SQL DECLARE cur_msgno CURSOR FOR stat_msgno; EXEC SQL WHENEVER NOT FOUND DO BREAK;//当循环时,没有数据则break.此语句要写在循环语句上面 for(;;){ EXEC SQL FETCH cur_ifinfo INTO :IFCodeStr :ind_IFCode; ...... if(strcmp(IFCodeStr, "") != 0){ EXEC SQL OPEN cur_msgno USING :IFCodeStr; for(;;){ EXEC SQL FETCH cur_msgno INTO :i_dataitem, :msgnoStr, :msgposStr, :msglenStr; } //EXEC SQL CLOSE cur_msgno;此处关闭将会导致无效游标的错误 }else{ ..... } } EXEC SQL CLOSE cur_msgno; EXEC SQL CLOSE cur_ifinfo; EXEC SQL WHENEVER NOT FOUND CONTINUE;//需变更回<NOT FOUND>的处理方式?
关闭游标需要在二层遍历游标之外。