Oracle RefCursor 的参数问题

发布于 2024-07-29 16:11:28 字数 1557 浏览 8 评论 0原文

我正在使用 ODP.NET(从 Microsoft 的提供商迁移),并且我陷入了返回引用游标的存储过程的困境。 我有以下 PL/SQL 过程(我对其进行了一些更改以使其更通用):

PROCEDURE MyProc(parameter_no1 IN NUMBER, parameter_no2 IN NUMBER, RETCURSOR OUT ret_type) AS
BEGIN
  OPEN RETCURSOR FOR
  SELECT   ad.logo logo 
  FROM    tab_a a, tab_h h 
  WHERE  a.id IS NOT NULL 
  AND    a.h_id = h.id 
  AND    a.no1 = parameter_no1
  AND    a.no2= parameter_no2;
END HanteraLogotype;

然后我有以下 C# 代码来调用它:

internal void RefCursorDataReader()
{
  OracleCommand cmd = new OracleCommand("ABC$MYPACKAGE.MyProc", new OracleConnection(_constr));
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Connection.Open();
  cmd.BindByName = true;

  OracleParameter p = cmd.Parameters.Add("parameter_no1", OracleDbType.Decimal);
  p.Value = 12345678;
  p.Direction = ParameterDirection.Input;

  p = cmd.Parameters.Add("parameter_no2", OracleDbType.Decimal);
  p.Value = 123456;
  p.Direction = ParameterDirection.Input;

  p = cmd.Parameters.Add("RETCURSOR", OracleDbType.RefCursor);
  p.Direction = ParameterDirection.Output;

  OracleDataReader reader = cmd.ExecuteReader();

  if (reader.Read())
  {
    System.Diagnostics.Debug.WriteLine(reader[0].GetType().ToString());
  }

  cmd.Connection.Close();
}

当我运行此过程时,我不断收到此异常:

ORA-03106: 致命的双任务通信协议错误

我尝试了许多不同的参数变体、它们的类型、顺序等,但似乎没有任何帮助。 引发异常的是 reader.Read()。 我非常感谢对此的帮助!

添加: ret_type 定义为:

TYPE ret_type 是参考游标;

I'm using ODP.NET (migrating from Microsoft's provider), and I have got stuck on a stored procedure that returns a refcursor. I have the following PL/SQL procedure (I have changed it a little bit to make it more general):

PROCEDURE MyProc(parameter_no1 IN NUMBER, parameter_no2 IN NUMBER, RETCURSOR OUT ret_type) AS
BEGIN
  OPEN RETCURSOR FOR
  SELECT   ad.logo logo 
  FROM    tab_a a, tab_h h 
  WHERE  a.id IS NOT NULL 
  AND    a.h_id = h.id 
  AND    a.no1 = parameter_no1
  AND    a.no2= parameter_no2;
END HanteraLogotype;

And then I have the folloing C# code to call it:

internal void RefCursorDataReader()
{
  OracleCommand cmd = new OracleCommand("ABC$MYPACKAGE.MyProc", new OracleConnection(_constr));
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Connection.Open();
  cmd.BindByName = true;

  OracleParameter p = cmd.Parameters.Add("parameter_no1", OracleDbType.Decimal);
  p.Value = 12345678;
  p.Direction = ParameterDirection.Input;

  p = cmd.Parameters.Add("parameter_no2", OracleDbType.Decimal);
  p.Value = 123456;
  p.Direction = ParameterDirection.Input;

  p = cmd.Parameters.Add("RETCURSOR", OracleDbType.RefCursor);
  p.Direction = ParameterDirection.Output;

  OracleDataReader reader = cmd.ExecuteReader();

  if (reader.Read())
  {
    System.Diagnostics.Debug.WriteLine(reader[0].GetType().ToString());
  }

  cmd.Connection.Close();
}

And when I run this, I keep getting this exception:

ORA-03106: fatal two-task communication protocol error

I have tried numerous different variations of parameters, their type, order etc, but nothing seems to help. It's the reader.Read() that throws the exception. I would really appreciate assistance on this one!

Added:
the ret_type is defined as:

TYPE ret_type IS REF CURSOR;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

扬花落满肩 2024-08-05 16:11:28

这看起来像一个错误。 3106 错误是一个不应该发生的严重错误。 我确信有一个解决方法!

询问 ODP.NET 问题的最佳地点是 OTN ODP.NET 论坛。 如果我是你,我会在那里发布:

http:// /forums.oracle.com/forums/forum.jspa?forumID=146&start=0

还要在该特定论坛中搜索“3106”

That looks like a bug. The 3106 error is a bad error that should never happen. I'm sure there's a workaround though!!

The best place to ask ODP.NET questions is over on the OTN ODP.NET forum. If I were you I would post this over there:

http://forums.oracle.com/forums/forum.jspa?forumID=146&start=0

Also search that particular forum for "3106"

风向决定发型 2024-08-05 16:11:28

我升级到11G ODP.NET

I upgraded to 11G ODP.NET

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