我对使用 OracleDataReader(Oracle.DataAccess.Client) 的 Oracle 存储过程的输出数据有疑问。
程序:
procedure LOAD_BL_REQ_2(P_XML CLOB, P_XML_OUT out CLOB) is
BEGIN
P_XML_OUT := 'TEST1111';
exception
when others then
P_XML_OUT := 'LOAD_BL_REQ: Error'|| SQLERRM;
END;
C#代码:
OracleCommand cmd = new OracleCommand();
cmd.Connection = OraConnection;
cmd.CommandText = "IBS.BNT_EQ.LOAD_BL_REQ_2";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
OracleParameter result = new OracleParameter();
result.ParameterName = "P_XML_OUT";
result.OracleDbType = OracleDbType.Clob;
result.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(result);
OracleParameter XMLString = new OracleParameter();
XMLString.ParameterName = "P_XML";
XMLString.OracleDbType = OracleDbType.Varchar2;
XMLString.Direction = System.Data.ParameterDirection.Input;
OracleDataReader dr;
cmd.Transaction = OraConnection.BeginTransaction();
try
{
XMLString.Value = XML;
cmd.Parameters.Add(XMLString);
dr = cmd.ExecuteReader();
cmd.Transaction.Commit();
}
catch (OracleException ex)
{
cmd.Transaction.Rollback();
Log(2, "Transaction fail, exception: " + ex.ToString());
ORADisconnect();
return "";
}
在调试过程中,我看到了博士:
Depth: 0
FetchSize: 131072
FieldCount: 0
HasRows: false
对于测试,我添加计数代码:
while (dr.Read())
{
count++;
}
计数在任何时候都是 0。
此代码(例如):
if(dr.IsDBNull(0))
{
//etc...
}
或者
OracleClob oclob;
oclob = dr.GetOracleClob(0);
返回异常:
dr.isdbnull exception: System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Oracle.DataAccess.Client.OracleDataReader.IsDBNull(Int32 i)
at GlobalFunc.ORA_BlackList_Test(String XML) in c:\inetpub\project\App_Code\GlobalFunc.cs:line 474
最后我需要从 Oracle SP 检索 CLOB 数据,但现在在这一步停止。使用:Visual Studio 2012、ASP.Net(网络项目,但我将此代码写入 WinForms 应用程序并遇到同样的问题)、oracle.dataaccess.dll 4.112.3.0