使用“Oracle.DataAccess”在 C# 中调用 Oracle 存储过程(带参数)

发布于 2024-10-24 16:36:37 字数 1028 浏览 2 评论 0原文

因此,我尝试从我的 C# .NET 应用程序调用 Oracle 存储过程。我能找到的大多数在线参考资料都建议“使用 System.Data.OracleClient;”,但 .Net 3.5 无法识别该命名空间,因此我使用“Oracle.DataAccess.Client”。

下面是我的代码的一些释义,之前设置和测试的名为“myConn”的 OracleConnection 已经填充了参数“:arg_myArg”(如果重要的话,它是一个数字):

command.Connection = myConn;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "exec mySchema.myProc(:arg_myArg)"
command.ExecuteNonQuery();

诀窍是该过程按设计不返回任何内容,它只是填充了我从中提取的另一个表。但是,当我尝试运行上面的代码时,我在最后一行收到“OracleException”并给出此错误:

ORA-06550: line 1, column 13:
PLS-00103: Encountered the symbol "MYSCHEMA" when expecting one of the following:

   := . ( @ % ;
The symbol ":=" was substituted for "MYSCHEMA" to continue.

从命令中删除“exec”会出现此错误:

ORA-06550: line 1, column 8:
PLS-00801: internal error [22503]
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored

有什么想法吗? I我很乐意澄清任何事情

这是我第一次在 stackoverflow.com 上发帖,也是我从事这份工作的最后一周,所以我感谢您的理解和相对仓促地解决这个问题

So I'm trying to call an Oracle stored procedure from my C# .NET application. Most online references I can find suggest "using System.Data.OracleClient;", but .Net 3.5 doesn't recognize that namespace so I'm using "Oracle.DataAccess.Client" instead.

Here's some paraphrasing of my code below, with a previously setup and tested OracleConnection called 'myConn' already filled with parameter ':arg_myArg' (it's a number, if that matters):

command.Connection = myConn;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "exec mySchema.myProc(:arg_myArg)"
command.ExecuteNonQuery();

The trick is that the procedure returns nothing by design, it simply populates a different table which I pull from. However, when I try to run the code above, I get a 'OracleException' on the final line and gives this error:

ORA-06550: line 1, column 13:
PLS-00103: Encountered the symbol "MYSCHEMA" when expecting one of the following:

   := . ( @ % ;
The symbol ":=" was substituted for "MYSCHEMA" to continue.

Removing the "exec" from the command gives this error instead:

ORA-06550: line 1, column 8:
PLS-00801: internal error [22503]
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored

Any ideas? I'd be happy to clarify anything

This is my first time posting on stackoverflow.com and my last week at this job, so I appreciate your understanding and relative haste with figuring this out

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

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

发布评论

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

评论(1

扶醉桌前 2024-10-31 16:36:37

我认为你需要这样的东西

command.Connection = myConn;
command.CommandType = CommandType.StoredProcedure;  
command.CommandText = "mySchema.myProc";  // the proc name   
command.Parameters.Add(/* TODO: Add parameter here */); 
command.ExecuteNonQuery();

I think you need to something like this

command.Connection = myConn;
command.CommandType = CommandType.StoredProcedure;  
command.CommandText = "mySchema.myProc";  // the proc name   
command.Parameters.Add(/* TODO: Add parameter here */); 
command.ExecuteNonQuery();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文