的結束,我不能在我的代碼找出問題:甲骨文PRO * C:取處理光標
/* 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也被執行。
感謝您幫助我解決這個問題。
爲什麼使用光標? – Arion 2012-04-09 00:05:38
爲什麼不呢?這是做這件事的傳統方式。你有更好的主意嗎? – iPadDevloperJr 2012-04-09 00:07:41
讓我以另一種方式詢問..做光標的目的是什麼? – Arion 2012-04-09 00:13:22