调用以直接 PL/SQL 形式返回引用游标的 Oracle 包过程
我有一个 Oracle 10g 数据库,可以从 ASP.NET 应用程序访问该数据库。尽管我在许多不同方面大量使用 SQL Server 并大量使用 Oracle 进行查询和报告,但这是我第一次使用 Oracle 作为应用程序的 OLTP 数据库。
包中的数据库级过程通常采用以下形式:
-- TYPE refcur IS REF CURSOR;
PROCEDURE get_some_stuff(o_cursor OUT refcur, p_param1 IN INTEGER, p_param2 IN INTEGER) IS
BEGIN
OPEN o_cursor FOR
SELECT whatever
FROM whatever
END
我假设这样做是为了 ADO.NET 层能够使用输出参数中的游标,据我所知,这是可接受的最佳方式从 .NET 调用 Oracle 过程的练习。
例如,在 SQL Server 中,我们没有显式引用游标,如果过程返回一个结果集(或多个结果集),则可以在 ADO.NET 和 SSMS 中作为输出结果集进行访问,并且您可以简单地测试通过执行 EXEC spname param1, param2
来操作 SP。
我遇到的问题是,我不知道如何在 Toad 中的 SQL 中直接调用这些,例如,能够在进入应用程序之前首先在 PL/SQL 级别测试更改。我非常习惯能够在 SQL Server 中练习甚至重新混合存储过程和函数,以便能够重构数据库接口层,而不影响应用程序级代码的外部接口。
I've got an Oracle 10g database which is accessed from an ASP.NET application. Although I've used SQL Server heavily in many different aspects and Oracle for querying and reporting, this is my first time using Oracle as the OLTP database for an application.
The database-level procedures in the packages are typically of the form:
-- TYPE refcur IS REF CURSOR;
PROCEDURE get_some_stuff(o_cursor OUT refcur, p_param1 IN INTEGER, p_param2 IN INTEGER) IS
BEGIN
OPEN o_cursor FOR
SELECT whatever
FROM whatever
END
I assume these are done this way for the benefit of the ADO.NET layer able to use the cursor from the output param and it is my understanding that this is the acceptable best practice for calling Oracle procs from .NET.
In SQL Server, for example, we don't have explicit ref cursors, if a proc returns a result set (or several result sets), that's accessible as an output result set in both ADO.NET and SSMS, and you can simply test the SPs by doing EXEC spname param1, param2
.
The problem I'm having is that I don't know how to call these directly in SQL in Toad, for example, to be able to test changes at the PL/SQL level first before going to the app. I'm very used to being able to exercise and even re-mix stored procs and functions in SQL Server to be able to refactor the database interface layer without affecting the external interface to application-level code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看 OMG Ponies 发布的链接,但您可以做的就是
将其包装在它将运行的匿名块广告中。我使用 SQL Developer(强烈推荐,免费,有大量支持)或 SQL plus,所以我无法帮助使用 TOAD,但我希望它是相同的。在 SQL Developer 中(如果没记错的话,在 SQL Navigator 中)您只需右键单击您想要的包/方法,它就会为您创建脚本。
在蟾蜍和导航器中,我相信您可以在漂亮的网格中获得参考光标,而在开发人员中,您可以在文本中获得它。
SQL Developer 也可以进行单元测试
look at the link that OMG Ponies posted, but what you can do is
you pretty much just wrap it in a anonymous block ad it will run. I use SQL Developer (highly recommmend, free with plenty of support) or SQL plus so I cannot help with TOAD, but I would expect it to be the same. In SQL Developer (and in SQL Navigator if memory serves correct) you can simply right click the package/method you wish and it will create the script for you.
in toad and navigator I believe you may be able to get the ref cursor in a pretty grid while in developer you get it in text.
SQL Developer you can unit test as well
试试这个:
分享和享受。
Try this:
Share and enjoy.
我找到了一种更简单的方法...尝试一下(这也会为您生成脚本)
在过程编辑器中,加载您的过程。点击闪电
执行bolt,你会看到设置参数窗口,这是
也可以通过 Proc Editor 工具栏上的按钮使用
其上闪电旁边的图像类似于 (...)。单击
输出选项按钮,您将看到您的选项。如果这是一个弱参考
那么你必须使用内存网格选项。结果转到
执行后,光标结果选项卡位于 PE 底部。
http://toad.10940.n7.nabble .com/display-ref-cursor-in-toad-td1427.html
I found an easier way to this ...try it (This will also generate script for you)
In the Procedure Editor, load your procedure. Click on the lightning
bolt to execute and you will see the Set Parameters window, which is
also available via the button on the Proc Editor toolbar that has an
image similar to (...) on it, next to the lightning bolt. Click on the
output options button and you'll see your options. If this is a weak ref
cursor then you must use the in-memory grid option. Results go to the
cursor results tab at the bottom of the PE after you execute.
http://toad.10940.n7.nabble.com/display-ref-cursor-in-toad-td1427.html