调用 Oracle 存储过程。获取“未找到数据”例外
我试图调用一个返回 XMLType 数据的 Oracle 存储过程,但我收到的只是“未找到数据异常”。表里有数据。我已经检查过了,然后再次检查。 我的调用存储过程的代码有问题吗?也许有些显而易见的事情,我完全失踪了。
using (OracleConnection dbc = new OracleConnection("Data Source=test; User ID=user; Password=pwd"))
{
dbc.Open();
using (DbTransaction trans = dbc.BeginTransaction())
{
try
{
DbCommand comm = dbc.CreateCommand();
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "TestStoredProcedure";
comm.Transaction = trans;
OracleParameter returnParam = new OracleParameter("result", OracleDbType.XmlType);
returnParam.Direction = ParameterDirection.ReturnValue;
comm.Parameters.Add(returnParam);
OracleParameter param1 = new OracleParameter("param1", OracleDbType.Varchar2);
param1.Direction = ParameterDirection.Input;
param1.Size = 70;
param1.Value = "testing";
comm.Parameters.Add(param1);
OracleParameter param2 = new OracleParameter("param2", OracleDbType.Varchar2);
param1.Direction = ParameterDirection.Input;
param1.Size = 70;
param1.Value = "testing";
comm.Parameters.Add(param2);
OracleParameter param3 = new OracleParameter("param3", OracleDbType.Date);
param1.Direction = ParameterDirection.Input;
param1.Value = Convert.ToDateTime("1/18/2011 12:00:00 AM");
comm.Parameters.Add(param3);
comm.ExecuteNonQuery(); //exception at this line
OracleXmlType oracleXml = (OracleXmlType)comm.Parameters["result"].Value;
XmlDocument xmlDoc = oracleXml.GetXmlDocument();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
存储过程:
declare
-- Non-scalar parameters require additional processing
result sys.xmltype;
begin
-- Call the function
result := mktadmin.test_package.test(param1 => :testval1,
param2 => :testval2,
param3 => :testval3);
end;
编辑:忽略名称中的任何差异。我必须编辑它们才能发布在这里。
I'm trying to call an Oracle Stored Procedure which returns XMLType data, but all I receive is a 'No Data Found Exception'. The table has data. I have checked that, and then double checked.
Is there something wrong in my code that calls the stored procedure. Maybe something obvious, I am completely missing.
using (OracleConnection dbc = new OracleConnection("Data Source=test; User ID=user; Password=pwd"))
{
dbc.Open();
using (DbTransaction trans = dbc.BeginTransaction())
{
try
{
DbCommand comm = dbc.CreateCommand();
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "TestStoredProcedure";
comm.Transaction = trans;
OracleParameter returnParam = new OracleParameter("result", OracleDbType.XmlType);
returnParam.Direction = ParameterDirection.ReturnValue;
comm.Parameters.Add(returnParam);
OracleParameter param1 = new OracleParameter("param1", OracleDbType.Varchar2);
param1.Direction = ParameterDirection.Input;
param1.Size = 70;
param1.Value = "testing";
comm.Parameters.Add(param1);
OracleParameter param2 = new OracleParameter("param2", OracleDbType.Varchar2);
param1.Direction = ParameterDirection.Input;
param1.Size = 70;
param1.Value = "testing";
comm.Parameters.Add(param2);
OracleParameter param3 = new OracleParameter("param3", OracleDbType.Date);
param1.Direction = ParameterDirection.Input;
param1.Value = Convert.ToDateTime("1/18/2011 12:00:00 AM");
comm.Parameters.Add(param3);
comm.ExecuteNonQuery(); //exception at this line
OracleXmlType oracleXml = (OracleXmlType)comm.Parameters["result"].Value;
XmlDocument xmlDoc = oracleXml.GetXmlDocument();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
The stored procedure:
declare
-- Non-scalar parameters require additional processing
result sys.xmltype;
begin
-- Call the function
result := mktadmin.test_package.test(param1 => :testval1,
param2 => :testval2,
param3 => :testval3);
end;
EDIT: Ignore any discrepancy in names. I had to edit them to post here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在覆盖 param2 和 param3 部分分配中的 param1 属性。
Looks like you are overwriting param1 properties in the param2 and param3 section assignments.
查看存储过程会很有用。当执行
select into
但没有产生任何结果时,您通常会收到no data found
错误。It would be useful to see the stored procedure. You usually get the
no data found
error when doing aselect into
that yields no results.