【原因及解决办法】C#报错ORA-00604:递归SQL级别1出现
错误,ORA-01000。。。
记录⼀下今天遇到的⼀个Oracle 错误 :ORA-00604: 递归 SQL 级别 1 出现错误,ORA-01000: 超出打开游标的最⼤数
医院运⾏的接⼝,最近频繁出现这个错误,⼀开始以为是游标最⼤数不够⼤经过以下SQL查询结果为 300,第⼀想到的就是修改最游标最⼤数
⽅式⼀
从数据库游标最⼤数修改⼊⼿,不过这个⽅法治标不治本。
--结果 300
select value from v$parameter where name = 'open_cursors'
--加⼤游标数
alter system set open_cursors=2000 scope=both;
⽅式⼆
从程序代码⼊⼿查问题,发现有⼀段循环处理如下:
问题就出在 dbhelper.ExecQuery(sql_fee_num, ref resultList_fee_num)
当resultList.Tables[0].Rows.Count 循环数⽐较⼩时,代码运⾏正常。当循环数超过⼀定值(数据库当前游标最⼤数:300),代码就会出错。提⽰:ORA-01000: 超出打开游标的最⼤数
这是因为Oracle数据库中打开的游标最⼤数为⼀定值,例如300,当代码中dbhelper.ExecQuery函数执⾏时, 循环中⼀个Command占⽤了⼀个数据库游标,执⾏的循环超过这个数时就会产⽣游标数⽬溢出错误。
//取各值:
for (int i = 0; i < resultList.Tables[0].Rows.Count; i++)
{
ls_label = resultList.Tables[0].Rows[i][0].ToString();
ls_ctype = resultList.Tables[0].Rows[i][1].ToString();
ls_doctor = resultList.Tables[0].Rows[i][2].ToString();
ls_doctor_id = resultList.Tables[0].Rows[i][3].ToString();
oracle游标的使用
//
string sql_fee_num = @"这⾥是⼀段SQL";
//问题出现在这⾥ dbhelper.ExecQuery(sql_fee_num, ref resultList_fee_num)
if (dbhelper.ExecQuery(sql_fee_num, ref resultList_fee_num) == 0)
{
for (int j = 0; j < resultList_fee_num.Tables[0].Rows.Count; j++)
{
ls_fee = resultList_fee_num.Tables[0].Rows[j][0].ToString();
ls_reg = resultList_fee_num.Tables[0].Rows[j][1].ToString();
}
}
}
解决办法:
在ExecQuery(sql_str,ref ds)函数中每次执⾏完OracleCommand,都将command.dispose()下,释放掉这个资源就好了
try
{
//command 处理
}
catch (Exception)
{
//异常处理
throw;
}
finally
{
command.Dispose();            }