如何避免此代码出现“超出游标限制”错误?

时间:2011-11-27 14:04:40

标签: c# sql oracle ado.net plsql

foreach (string num in ld2.Keys)
{
  double state;
  int i;

  for (i = 0; i < states.Count; i++)
  {
    cmd = mdb.getCommand("select value V " +
                         "  from TAB_CHART_DATA " + 
                         " where TIMESTAMP = (select max(TIMESTAMP) " +
                         "                      from TAB_CHART_DATA " + 
                         "                     where chart_type= " + chart_type + 
                         "                       and upper(upper(state)) = '" + states[i] + "' " +
                         "                       and CSIS_ID = " + CSISPID + 
                         "                       and baselinecode like '" + num + "'" +
                         "                   ) " +
                         "   and chart_type = " + chart_type + 
                         "   and upper(state) = '" + states[i] + "' " +
                         "   and CSIS_ID = " + CSISPID + 
                         "   and baselinecode like '" + num + "'"
                        );

    state = mdb.ExecSQLAndGetFirstInt(cmd);
  }

}

此循环运行超过3000次。

1 个答案:

答案 0 :(得分:3)

获取一个查询中的所有行并循环遍历代码中的结果集,而不是打开游标并终止数据库。