如何使用 RefCursor 返回类型测试 Oracle 存储过程?
我正在寻找有关如何在 SQL Developer 或 Embarcardero Rapid XE2 中测试 Oracle 存储过程的良好解释。谢谢。
I'm looking for a good explanation on how to test an Oracle stored procedure in SQL Developer or Embarcardero Rapid XE2. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
类似的东西
可以在 SQL*Plus 或 SQL Developer 中工作。我没有任何使用 Embarcardero Rapid XE2 的经验,所以我不知道它是否支持这样的 SQL*Plus 命令。
Something like
will work in SQL*Plus or SQL Developer. I don't have any experience with Embarcardero Rapid XE2 so I have no idea whether it supports SQL*Plus commands like this.
像这样的东西可以让您在几乎任何客户端上测试您的过程:
基本上,您的测试工具需要支持 SYS_REFCURSOR 变量的定义以及在传递您定义的变量时调用您的过程的能力,然后循环遍历游标结果集。 PL/SQL 可以做到这一切,并且匿名块易于设置和维护,具有相当的适应性,并且对于使用 PL/SQL 的任何人来说都非常可读。
另一种虽然相似的方法是构建一个执行相同操作的命名过程,并假设客户端有一个调试器(如 SQL Developer、PL/SQL Developer、TOAD 等),然后您可以单步执行。
Something like this lets you test your procedure on almost any client:
Basically, your test harness needs to support the definition of a
SYS_REFCURSOR
variable and the ability to call your procedure while passing in the variable you defined, then loop through the cursor result set. PL/SQL does all that, and anonymous blocks are easy to set up and maintain, fairly adaptable, and quite readable to anyone who works with PL/SQL.Another, albeit similar way would be to build a named procedure that does the same thing, and assuming the client has a debugger (like SQL Developer, PL/SQL Developer, TOAD, etc.) you could then step through the execution.
在 SQL Developer 中,您可以右键单击包主体,然后选择“运行”。 “运行 PL/SQL”窗口将允许您编辑 PL/SQL 块。单击“确定”将出现一个标题为“输出变量 - 日志”的窗口窗格,其中包含一个输出变量选项卡。您可以在左侧选择输出变量,结果显示在右侧。非常方便快捷。
我已经将 Rapid 与 T-SQL 结合使用,我认为有一些与此类似的东西。
编写您自己的 delcare-begin-end 脚本,在其中循环遍历光标,就像 DCookie 的示例一样,始终是一个很好的练习。它适用于任何东西,并且您会知道您的代码可以工作。
In SQL Developer you can right-click on the package body then select RUN. The 'Run PL/SQL' window will let you edit the PL/SQL Block. Clicking OK will give you a window pane titled 'Output Variables - Log' with an output variables tab. You can select your output variables on the left and the result is shown on the right side. Very handy and fast.
I've used Rapid with T-SQL and I think there was something similiar to this.
Writing your own delcare-begin-end script where you loop through the cursor, as with DCookie's example, is always a good exercise to do every now and then. It will work with anything and you will know that your code works.
在 Toad 10.1.1.8 中,我使用:
然后,作为脚本执行。
In Toad 10.1.1.8 I use:
Then, Execute as Script.
然后编写一个函数来调用您的存储过程,
然后您可以在 SQLDeveloper 编辑器中运行此 SQL 查询。
您将在控制台中看到结果,右键单击它并选择单个记录视图并编辑结果,您可以看到引用光标返回的所有记录。
and then write a function lie this which calls your stored procedure
then you can run this SQL query in the SQLDeveloper editor.
you will see the result in the console right click on it and cilck on single record view and edit the result you can see the all the records that were returned by the ref cursor.
我想这个链接对你来说就足够了。我在寻找执行oracle程序的方法时发现的。
简短描述:
I think this link will be enough for you. I found it when I was searching for the way to execute oracle procedures.
Short Description: