pro*c里嵌套游标报错;ORA-01002: fetch out of sequence

ali_sure 2007-02-01 09:37:20
sprintf(v_sqlString,"select cust_id,nvl(cust_type_code,-1),nvl(cust_name,-1) from cust partition(p200701) where rownum<10");
printf("the v_sqlString is %s\n",v_sqlString);
EXEC SQL prepare pre_cursor from :v_sqlString;
EXEC SQL declare cursor_l cursor for pre_cursor;
EXEC SQL open cursor_l;
printf("333333333333333333333333333333333333333333333333333333\n");
while(1)
{
memset(&zmx,0,structSize);
exec sql fetch cursor_l into
:cust_id,
:cust_type_code,
:cust_name;
int gh_num=0;
int xlt_num=0;
int kd_num=0;
if(sqlca.sqlcode==1403) break;
if((sqlca.sqlcode<0)&&(sqlca.sqlcode!=-1405))
{
printf("error2:%d\n",sqlca.sqlcode);
exec sql close cursor_l;
return 2;
}


zmx.cust_id=cust_id;
strcpy(zmx.cust_type_code,cust_type_code);
strcpy(zmx.cust_name,cust_name);
zmx.month_id=200701;
printf("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n");

sprintf(v_sqlString2,"select acc_nbr,serv_type_code from serv partition(p200701) where cust_id = %d",zmx.cust_id);
printf("the v_sqlString2 is %s\n",v_sqlString2);
EXEC SQL select count(*) into :count from serv partition(p200701) where cust_id=:zmx.cust_id;
printf("%d\n",count);
count_cnt=count;
int a=0;
EXEC SQL prepare pre_cursor from :v_sqlString2;
EXEC SQL declare cursor_2 cursor for pre_cursor;
EXEC SQL open cursor_2;
printf("%d\n111",a);
if(a>=count_cnt) continue;
while(a<count_cnt)
{a++;printf("%d\n",a);
/*
k++;
if (k>5) break;
printf("the k is %d",k);
*/
exec sql fetch cursor_2 into :acc_nbr,:serv_type_code;
if((sqlca.sqlcode<0)&&(sqlca.sqlcode!=-1405))
{
printf("error3:%d\n",sqlca.sqlcode);
exec sql close cursor_2;
return 2;
}

if(sqlca.sqlcode == 1403) break;
EXEC SQL select level_3_name into :tmp_type from serv_type where serv_type_code=:serv_type_code ;

printf("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n");

if (strcmp(tmp_type,"固定电话")==0)
{
gh_num+=1;
if(strcmp(zmx.gh_1,"00000000000000000000")==0)
strcpy(zmx.gh_1,acc_nbr);
else if(strcmp(zmx.gh_2,"00000000000000000000")==0)
strcpy(zmx.gh_2,acc_nbr);
else if(strcmp(zmx.gh_3,"00000000000000000000")==0)
strcpy(zmx.gh_3,acc_nbr);
else if(strcmp(zmx.gh_4,"00000000000000000000")==0)
strcpy(zmx.gh_4,acc_nbr);
else if(strcmp(zmx.gh_5,"00000000000000000000")==0)
strcpy(zmx.gh_5,acc_nbr);
else if(strcmp(zmx.gh_6,"00000000000000000000")==0)
strcpy(zmx.gh_6,acc_nbr);
else if(strcmp(zmx.gh_7,"00000000000000000000")==0)
strcpy(zmx.gh_7,acc_nbr);
else if(strcmp(zmx.gh_8,"00000000000000000000")==0)
strcpy(zmx.gh_8,acc_nbr);
else if(strcmp(zmx.gh_9,"00000000000000000000")==0)
strcpy(zmx.gh_9,acc_nbr);
else if(strcmp(zmx.gh_10,"00000000000000000000")==0)
strcpy(zmx.gh_10,acc_nbr);
else
break;
}
else if(strcmp(tmp_type,"小灵通")==0)
{
xlt_num+=1;
if(strcmp(zmx.xlt_1,"00000000000000000000")==0)
strcpy(zmx.xlt_1,acc_nbr);
else if(strcmp(zmx.xlt_2,"00000000000000000000")==0)
strcpy(zmx.xlt_2,acc_nbr);
else if(strcmp(zmx.xlt_3,"00000000000000000000")==0)
strcpy(zmx.xlt_3,acc_nbr);
else if(strcmp(zmx.xlt_4,"00000000000000000000")==0)
strcpy(zmx.xlt_4,acc_nbr);
else if(strcmp(zmx.xlt_5,"00000000000000000000")==0)
strcpy(zmx.xlt_5,acc_nbr);
else if(strcmp(zmx.xlt_6,"00000000000000000000")==0)
strcpy(zmx.xlt_6,acc_nbr);
else if(strcmp(zmx.xlt_7,"00000000000000000000")==0)
strcpy(zmx.xlt_7,acc_nbr);
else if(strcmp(zmx.xlt_8,"00000000000000000000")==0)
strcpy(zmx.xlt_8,acc_nbr);
else if(strcmp(zmx.xlt_9,"00000000000000000000")==0)
strcpy(zmx.xlt_9,acc_nbr);
else if(strcmp(zmx.xlt_10,"00000000000000000000")==0)
strcpy(zmx.xlt_10,acc_nbr);
//else
//break;
}
else if(strcmp(tmp_type,"宽带")==0)
{
kd_num+=1;
if(strcmp(zmx.kd_1,"00000000000000000000")==0)
strcpy(zmx.kd_1,acc_nbr);
else if(strcmp(zmx.kd_2,"00000000000000000000")==0)
strcpy(zmx.kd_2,acc_nbr);
else if(strcmp(zmx.kd_3,"00000000000000000000")==0)
strcpy(zmx.kd_3,acc_nbr);
else if(strcmp(zmx.kd_4,"00000000000000000000")==0)
strcpy(zmx.kd_4,acc_nbr);
else if(strcmp(zmx.kd_5,"00000000000000000000")==0)
strcpy(zmx.kd_5,acc_nbr);
else if(strcmp(zmx.kd_6,"00000000000000000000")==0)
strcpy(zmx.kd_6,acc_nbr);
else if(strcmp(zmx.kd_7,"00000000000000000000")==0)
strcpy(zmx.kd_7,acc_nbr);
else if(strcmp(zmx.kd_8,"00000000000000000000")==0)
strcpy(zmx.kd_8,acc_nbr);
else if(strcmp(zmx.kd_9,"00000000000000000000")==0)
strcpy(zmx.kd_9,acc_nbr);
else if(strcmp(zmx.kd_10,"00000000000000000000")==0)
strcpy(zmx.kd_10,acc_nbr);
//else
//break;
}

zmx.gh_num= gh_num;
zmx.xlt_num=xlt_num;
zmx.kd_num=kd_num;
printf("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n");



printf("%s--------%s\n",acc_nbr,serv_type_code);
printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");

count--;

}
EXEC SQL close cursor_2;


printf("continue");
if(a>=count_cnt)
{printf("continue2");
continue;}


fprintf(hFile,"%d,",zmx.cust_id);
fprintf(hFile,"%s,",zmx.cust_type_code);
fprintf(hFile,"%s,",zmx.cust_name);
fprintf(hFile,"%ld,",zmx.month_id);
fprintf(hFile,"%d,",zmx.gh_num);
fprintf(hFile,"%d,",zmx.xlt_num);
fprintf(hFile,"%d,",zmx.kd_num);
fprintf(hFile,"%s,",zmx.gh_1);
fprintf(hFile,"%s,",zmx.gh_2);
fprintf(hFile,"%s,",zmx.gh_3);
fprintf(hFile,"%s,",zmx.gh_4);
fprintf(hFile,"%s,",zmx.gh_5);
fprintf(hFile,"%s,",zmx.gh_6);
fprintf(hFile,"%s,",zmx.gh_7);
fprintf(hFile,"%s,",zmx.gh_8);
fprintf(hFile,"%s,",zmx.gh_9);
fprintf(hFile,"%s,",zmx.gh_10);
fprintf(hFile,"%s,",zmx.xlt_1);
fprintf(hFile,"%s,",zmx.xlt_2);
fprintf(hFile,"%s,",zmx.xlt_3);
fprintf(hFile,"%s,",zmx.xlt_4);
fprintf(hFile,"%s,",zmx.xlt_5);
fprintf(hFile,"%s,",zmx.xlt_6);
fprintf(hFile,"%s,",zmx.xlt_7);
fprintf(hFile,"%s,",zmx.xlt_8);
fprintf(hFile,"%s,",zmx.xlt_9);
fprintf(hFile,"%s,",zmx.xlt_10);
fprintf(hFile,"%s,",zmx.kd_1);
fprintf(hFile,"%s,",zmx.kd_2);
fprintf(hFile,"%s,",zmx.kd_3);
fprintf(hFile,"%s,",zmx.kd_4);
fprintf(hFile,"%s,",zmx.kd_5);
fprintf(hFile,"%s,",zmx.kd_6);
fprintf(hFile,"%s,",zmx.kd_7);
fprintf(hFile,"%s,",zmx.kd_8);
fprintf(hFile,"%s,",zmx.kd_9);
fprintf(hFile,"%s\n",zmx.kd_10);

}
EXEC SQL close cursor_l;
...全文
1422 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andy__Huang 2009-03-05
  • 打赏
  • 举报
回复
ORA-01002: fetch out of sequence
查询一下系列,是不是已经用到了系列的最大值?
kawang008 2009-02-13
  • 打赏
  • 举报
回复
这么长看不了,可能是没有写游标找不到下一条数据时,退出循环
qiyousyc 2007-02-02
  • 打赏
  • 举报
回复
这么长的代码,那个能看,错误信息呢?
那里出错误呀
sailer_shi 2007-02-02
  • 打赏
  • 举报
回复
把抱错信息给出来呀,具体运行到哪里抱错的亚,只给代码

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧