一段select SQL,在PL/SQL中执行返回的记录是几百条,没有报错误
在C++程序里,使用OCI接口访问数据,
使用接口函数循环取下一条记录 OCIStmtFetch2(m_stmthp, m_errhp, 1, OCI_FETCH_NEXT, 1, OCI_DEFAULT);
返回记录时得到OCI_ERROR(=-1)
跟着使用OCIErrorGet((dvoid *)pErr, (ub4)1, (text *)NULL, &ora_err,
(unsigned char*)err_msg, (ub4)sizeof(err_msg), OCI_HTYPE_ERROR);
得到ora_err=1772,err_msg: ORA-01772:无效的数字
最杯具的一个问题是,在C++程序中,循环使用
while(true)
{
 int ret_code = OCIStmtFetch2(m_stmthp, m_errhp, 1, OCI_FETCH_NEXT, 1, OCI_DEFAULT);
 //当执行其他查询时,可以正常取下一条记录,
 //但是当执行这一个有问题的查询时,调试状态跟踪,似乎每次Fetch都是在取第一条,不会跳到第二条,以至最后一条
 //也就是说陷入死循环,无法跳出这个while   if(ret_code == OCI_NO_DATA)
   break;
}
数据库为oracle 10.2g.
求各位大侠帮忙分析原因。

解决方案 »

  1.   

    再加一个判断if(ret_code ==无效数字的错误代码)continue,还是怎么做,处理一下就okay了。
      

  2.   

    1楼说的方法不可行,除非使用break替代continue,但是会造成后续数据被忽略。
    现在的问题主要有两点:
    1、在PL/SQL dev中可以正常执行得到几百条记录
    2、在C++程序中OCIStmtFetch2(m_stmthp, m_errhp, 1, OCI_FETCH_NEXT, 1, OCI_DEFAULT);执行之后,好像位置不会指向下一条,总是指在记录集第一条,造成无限循环。贴一下相关sqlselect DevID, Violation,line_id,line_name, group_id, group_name,
           sum(case
                 when P > 0 and P < 10 then
                  1
                 else
                  0
               end) as PerLow,
           sum(case
                 when P >= 10 and P < 20 then
                  1
                 else
                  0
               end) as PerHighLow,
           sum(case
                 when P >= 20 and P < 50 then
                  1
                 else
                  0
               end) as PerLowHigh,
           sum(case
                 when P >= 50 then
                  1
                 else
                  0
               end) as PerHighHigh
     from view_pviolation a
     where line_id in (354,358)
     and a.AlarmDate >= '2011-04-05 00:00:00'
     and a.AlarmDate <= '2012-04-05 23:59:59'
     group by DevID,
              Violation,
              busline_id,
              busline_name,
              group_id,
              group_name------------------------------------
    create or replace view view_pviolation as
    select a.DevID,a.AlarmDate,a.Violation,
    (case when (a.cspeedlimit=0) or (a.cspeedlimit is null) then
     0
    else
     ((to_number(a.memo) - a.cspeedlimit) / a.cspeedlimit * 100)
    end) as p,c.busline_id,c.line_name,d.group_id,d.group_name from tab_violation a
    left join t_lndevs b on a.devid=b.dev_id
    left join t_lines c on b.line_id=c.line_id
    left join t_dgroups d on c.group_id=d.group_id;
      

  3.   

    问题的原因找到了
    原因在于取回结果绑定字段的时候,字段的顺序对应错了,导致绑定的变量类型和字段类型不一致,从而发生字符串数据转换到NUMBER失败的错误,于是就有了ORA-01722错误