调用 Oracle 存储过程。获取“未找到数据”例外

发布于 2024-10-17 21:02:57 字数 2153 浏览 2 评论 0原文

我试图调用一个返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇到 2024-10-24 21:02:58

看起来您正在覆盖 param2 和 param3 部分分配中的 param1 属性。

Looks like you are overwriting param1 properties in the param2 and param3 section assignments.

捎一片雪花 2024-10-24 21:02:58

查看存储过程会很有用。当执行select into但没有产生任何结果时,您通常会收到no data found错误。

It would be useful to see the stored procedure. You usually get the no data found error when doing a select into that yields no results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文