不带参数调用 Oracle 存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6752231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call Oracle stored procedure with no arguments
提问by chris
I'm trying to call an Oracle stored procedure that accepts no input parameters. However, when running the procedure, I get an error back that states
我正在尝试调用不接受输入参数的 Oracle 存储过程。但是,在运行该程序时,我收到一条错误消息,指出
PLS-00306: wrong number or types of arguments in call to 'MY_PROC'
To call the proc, I'm just entering the following text into TOra:
要调用 proc,我只需在 TOra 中输入以下文本:
BEGIN
SCHEMA.MY_PROC();
END;
I've also tried (same error though)
我也试过(虽然同样的错误)
EXEC SCHEMA.MY_PROC();
I'm familiar with MSSQL and I'm able to execute SP with no problem using SQL server, but I can't figure out how to do the same with Oracle. I can't view the actual code for the stored procedure, but from the limited documentation I have, it appears it accepts no input parameters and the return value is a ref cursor. I have a feeling that I need to pass in a ref cursor somehow, but everything I've tried in that regard has not worked.
我熟悉 MSSQL,并且可以使用 SQL 服务器毫无问题地执行 SP,但我不知道如何使用 Oracle 执行相同的操作。我无法查看存储过程的实际代码,但从我拥有的有限文档来看,它似乎不接受任何输入参数,并且返回值是一个引用游标。我有一种感觉,我需要以某种方式传入一个引用游标,但我在这方面尝试过的一切都没有奏效。
I just want to view the results of the SP as if I had done a SELECT
statement, that is, with the records populating the data grid in the results panel in the TOra interface.
我只想查看 SP 的结果,就好像我做了一个SELECT
语句,也就是说,记录填充了 TOra 界面结果面板中的数据网格。
回答by Justin Cave
It sounds like the procedure does have an OUT parameter (in Oracle, procedures do not return anything but can have OUT and IN OUT parameters, functions return something). So you would have to pass in a variable for that OUT parameter. Something like
听起来这个过程确实有一个 OUT 参数(在 Oracle 中,过程不返回任何东西,但可以有 OUT 和 IN OUT 参数,函数返回一些东西)。因此,您必须为该 OUT 参数传入一个变量。就像是
DECLARE
l_results SYS_REFCURSOR;
BEGIN
schema.my_proc( l_results );
END;
should successfully call the procedure. But then you want your GUI to display the results from that cursor. That, unfortunately, gets a little more complicated because now you're talking about a GUI-specific issue.
应该成功调用该过程。但是随后您希望您的 GUI 显示来自该光标的结果。不幸的是,这变得有点复杂,因为现在您正在谈论特定于 GUI 的问题。
I don't use TOra, so I don't know what you need to do in TOra to get the cursor to display. In SQL*Plus (or SQL Developer, Oracle's free GUI), you could do something like
我不使用 TOra,所以我不知道您需要在 TOra 中做什么才能使光标显示。在 SQL*Plus(或 SQL Developer,Oracle 的免费 GUI)中,您可以执行类似的操作
create or replace procedure my_proc( p_rc OUT SYS_REFCURSOR )
as
begin
open p_rc
for select 1 col1
from dual;
end;
/
variable rc refcursor;
exec my_proc( :rc );
print rc;
This creates a stored procedure with an OUT parameter that is a cursor, declares a host variable that can be passed in, and then prints the results.
这将创建一个带有 OUT 参数的存储过程,该参数是一个游标,声明一个可以传入的主变量,然后打印结果。