我无法弄清楚我的代码中的问题:
/* Declare a cursor for the FETCH statement. */
EXEC SQL DECLARE customer_cursor CURSOR FOR
SELECT CUSTOMER_ID, CUSTOMER_NAME
FROM CUSTOMER_TABLE
WHERE CUSTOMER_CARD_NUM = :argv[1];
if ( sqlca.sqlcode != 0 )
{
printf("Declare cursor failed\n");
return( sqlca.sqlcode );
}
EXEC SQL OPEN customer_cursor;
if ( sqlca.sqlcode != 0 )
{
printf("Open cursor failed\n");
return( sqlca.sqlcode );
}
EXEC SQL WHENEVER NOT FOUND GOTO no_match;
for ( ;; )
{
/* Fetching data */
EXEC SQL FETCH customer_cursor
INTO :var_customer_id, :var_customer_name;
if ( sqlca.sqlcode != 0 )
{
EXEC SQL CLOSE cust_data_cursor;
return ( sqlca.sqlcode );
}
/* Doing some stuff here */
processing_customer();
}
EXEC SQL CLOSE customer_cursor;
/* Handling the no data found here */
no_match:
printf("NO CUSTOMER MATCHING THIS CARD_NUM\n");
/* Some stuff */
......
return 1;
我的查询应该只返回一行或什么都不返回,当什么都不返回时一切正常,但是当匹配时,函数 processing_customer 被执行,奇怪的是 no_match 也被执行。
谢谢你帮我解决这个问题。