从 C# 调用 Oracle 存储过程?
如何从C#调用oracle中的存储过程?
How does one call a stored procedure in oracle from C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何从C#调用oracle中的存储过程?
How does one call a stored procedure in oracle from C#?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
请访问 Oracle 为 Microsoft OracleClient 开发人员建立的 ODP 站点:
http://www.oracle.com/technetwork/topics/dotnet/index -085703.html
下面还有一个示例代码,可以帮助您开始从 C# 到 Oracle 调用存储过程。 PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT 是基于 Oracle 构建的存储过程,接受参数 PUNIT、POFFICE、PRECEIPT_NBR 并在 T_CURSOR 中返回结果。
Please visit this ODP site set up by oracle for Microsoft OracleClient Developers:
http://www.oracle.com/technetwork/topics/dotnet/index-085703.html
Also below is a sample code that can get you started to call a stored procedure from C# to Oracle. PKG_COLLECTION.CSP_COLLECTION_HDR_SELECT is the stored procedure built on Oracle accepting parameters PUNIT, POFFICE, PRECEIPT_NBR and returning the result in T_CURSOR.
我现在已经获得了从 C# 调用过程所需的步骤
希望这会有所帮助
I have now got the steps needed to call procedure from C#
Hope this helps
它与非查询命令的机制基本相同:
存储过程
=
CommandType.StoredProcedure
那里有很多示例,Google 返回的第一个是这个
如果您的 SP 是函数,您的返回值参数必须位于参数集合中的第一个
It's basically the same mechanism as for a non query command with:
stored procedure
=
CommandType.StoredProcedure
There are plenty of examples out there, the first one returned by Google is this one
There's also a little trap you might fall into, if your SP is a function, your return value parameter must be first in the parameters collection
连接到 Oracle 很糟糕。这是一些带有 using 语句的更清晰的代码。许多其他示例不会在它们创建的对象上调用 IDisposable 方法。
Connecting to Oracle is ugly. Here is some cleaner code with a using statement. A lot of the other samples don't call the IDisposable Methods on the objects they create.
此代码非常适合我调用 oracle 存储过程
添加引用,方法是在解决方案资源管理器中右键单击您的项目名称>添加引用>.Net,然后添加命名空间。
然后将此代码粘贴到事件处理程序中
并且完成...使用 C# 进行快乐编码
This Code works well for me calling oracle stored procedure
Add references by right clicking on your project name in solution explorer >Add Reference >.Net then Add namespaces.
then paste this code in event Handler
And its Done...Happy Coding with C#
在 .Net 到版本 4 中,可以按照与 SQL Server 存储过程相同的方式完成此操作,但请注意,您需要:
有 此处的一些系统要求,您应该验证这些要求在您的场景中是否正常。
Microsoft 从.Net 4,因此未来将需要第三方提供商。考虑到这一点,您最好使用 Oracle Data Provider for .Net (ODP.NET) 来自 go 这个词 - 这具有 Microsoft 类中没有的优化。还有其他第三方选择,但 Oracle 在保留 .Net 开发人员方面拥有强大的既得利益,因此他们的选择应该很好。
In .Net through version 4 this can be done the same way as for SQL Server Stored Procs but note that you need:
There are some system requirements here that you should verify are OK in your scenario.
Microsoft is deprecating this namespace as of .Net 4 so third-party providers will be needed in the future. With this in mind, you may be better off using Oracle Data Provider for .Net (ODP.NET) from the word go - this has optimizations that are not in the Microsoft classes. There are other third-party options, but Oracle has a strong vested interest in keeping .Net developers on board so theirs should be good.
注意
您也可以使用以下语法:
,如果您设置
cmd.BindByName = False
(这是默认值),那么您必须按照命令中写入的顺序添加参数字符串,实际名称不相关。对于 cmd.BindByName = True ,参数名称必须匹配,顺序并不重要。如果是函数调用,命令字符串将如下所示:
Instead of
You can also use this syntax:
Note, if you set
cmd.BindByName = False
(which is the default) then you have to add the parameters in the same order as they are written in your command string, the actual names are not relevant. Forcmd.BindByName = True
the parameter names have to match, the order does not matter.In case of a function call the command string would be like this:
下面的 .NET Core 解决方案对我有用。注意,它使用的是OracleDataReader,而Oracle CommandType是CommandType.Text
.......
Below worked for me in .NET Core solution. Note that it uses OracleDataReader and Oracle CommandType is CommandType.Text
.......