我写了一个ecpg代码。我试图根据表中是否已存在元组,将元组插入表中。我正在编译时出现“错误:break语句不在循环内或切换”请帮忙 我在代码中评论了编译器显示错误的行
EXEC SQL DECLARE cursor4 CURSOR FOR
select count(*)
from works_on
where pno = :project
and essn = :ssn;
EXEC SQL OPEN cursor4;
EXEC SQL WHENEVER NOT FOUND DO BREAK;
while (SQLCODE==0)
{
EXEC SQL FETCH IN cursor4 INTO :cnt;
}
EXEC SQL CLOSE cursor4;
EXEC SQL BEGIN DECLARE SECTION;
const char *qry = "INSERT INTO WORKS_ON VALUES(?,?,?);";
EXEC SQL END DECLARE SECTION;
if (cnt == 0 )
{
EXEC SQL PREPARE mystmt from :qry;
exec sql execute mystmt using '123456789',3,5.0; // where i am getting error
}
答案 0 :(得分:0)
执行WHENEVER句子,直到它在代码中找到另一个WHENEVER。你必须在你的bucle之后取消 WHENVER NOT FOUND break 。
EXEC SQL DECLARE cursor4 CURSOR FOR
select count(*)
from works_on
where pno = :project
and essn = :ssn;
EXEC SQL OPEN cursor4;
EXEC SQL WHENEVER NOT FOUND DO BREAK;
while (SQLCODE==0)
{
EXEC SQL FETCH IN cursor4 INTO :cnt;
}
EXEC SQL WHENEVER NOT FOUND CONTINUE; //Add this line to your code.
EXEC SQL CLOSE cursor4;
EXEC SQL BEGIN DECLARE SECTION;
const char *qry = "INSERT INTO WORKS_ON VALUES(?,?,?);";
EXEC SQL END DECLARE SECTION;
if (cnt == 0 )
{
EXEC SQL PREPARE mystmt from :qry;
exec sql execute mystmt using '123456789',3,5.0;