显示来自oracle 10g存储过程的结果集
我正在使用 PL/SQL Developer,并且已经编写了一个过程来运行报告,并且我需要过程来输出结果集。
该过程接受输入参数并需要输出结果集。
我无法使用视图,因为该过程调用了多个 API,这些 API 接受我传递给该过程的参数。
我从大量搜索中了解到可以使用 ref_cursor 但我无法让 ti 工作。
该过程的简化版本是:
CREATE OR REPLACE PROCEDURE IFSINFO.SHORTAGE_SHEET (vSite IN VARCHAR2,
vBuyer IN VARCHAR2,
vSupplier IN VARCHAR2,
vCursor OUT SYS_REFCURSOR)
AS
BEGIN
OPEN vCursor FOR
SELECT blah blah blah blah blah blah;
END;
我尝试执行该过程并使用以下方式显示结果集:
BEGIN
vsite := 'S03';
vbuyer := 'AW';
vsupplier := '%';
vcursor refcursor;
IFSINFO.SHORTAGE_SHEET(vsite => :vsite,
vbuyer => :vbuyer,
vsupplier => :vsupplier,
vcursor => :vcursor);
print vcursor;
END;
并且:
variable rc refcursor;
exec IFSINFO.SHORTAGE_SHEET('S03','AW','TQ1',:rc2);
print rc2
但都不起作用。请有人告诉我我已经束手无策了。
谢谢 抢
I am using PL/SQL Developer and i have written a procedure to run a report and i need to procedure to output the resultset.
The procedure accepts input parameters and needs to output the resultset.
I cannot use a view because the procedure calls several APIs which accept the parameters i am passing into the procedure.
I understand from alot of searching that it's possible using ref_cursor but i cannot get ti to work.
A simplified version of the procedure is:
CREATE OR REPLACE PROCEDURE IFSINFO.SHORTAGE_SHEET (vSite IN VARCHAR2,
vBuyer IN VARCHAR2,
vSupplier IN VARCHAR2,
vCursor OUT SYS_REFCURSOR)
AS
BEGIN
OPEN vCursor FOR
SELECT blah blah blah blah blah blah;
END;
I have tried to execture the procedure and display the resultset using:
BEGIN
vsite := 'S03';
vbuyer := 'AW';
vsupplier := '%';
vcursor refcursor;
IFSINFO.SHORTAGE_SHEET(vsite => :vsite,
vbuyer => :vbuyer,
vsupplier => :vsupplier,
vcursor => :vcursor);
print vcursor;
END;
And also:
variable rc refcursor;
exec IFSINFO.SHORTAGE_SHEET('S03','AW','TQ1',:rc2);
print rc2
But neither work. please can someone advise i am at my wits end.
Thank you
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您执行此过程或在 SQLPLUS 中运行它时,您是否看到错误?
您可以按原样发布您的 sqlplus 会话吗?
PRINT 是 sqlplus 特定命令,不能在过程块内调用。如果您需要打印过程中引用游标的结果,那么您需要从中获取并以您需要的格式打印每条记录。
您还应该更改您的过程(或)过程调用以具有不同的变量名称。一般来说,我为所有输入变量添加“i_”前缀,为所有输出变量添加“o_”前缀。这样,您的过程声明将看起来像..
并且过程调用将是..
您不需要在这些变量的开头使用“:”,因为它们不是主机环境变量(这是您第二次执行的情况,使用SQLPLUS,您在过程调用中使用 sqlplus 变量“rc”)
Is there an error that you see when you execute this procedure or run it in SQLPLUS?
Can you post your sqlplus session as is?
PRINT is a sqlplus specific command and it cannot be called inside the procedural block. If you need to print the results of a refcursor inside a procedure , then you'll need to fetch from it and print each record in the format that you need.
You should also change your procedure (or) the procedure call to have different variable names.generallt, I prefix all input variables with "i_" and all output variables with "o_". This way, your procedure declaration would look like..
and the procedure call would be..
You need not use the ":" in the beginning for these variables since they are not host environment variables ( this is the case for your second execution using SQLPLUS where you use the sqlplus variable "rc" inside the procedure call)
在pl/sql Developer中对此进行了底层分析,代码如下。
创建一个对象来存储结果集
创建一个类型作为上述对象的表
创建一个包来执行 SQL
创建包体来执行 SQL
执行并输出结果集的代码
SELECT * FROM TABLE(ABC.TEST_RPT.get_report ('','',''))
To the bottom of this in pl/sql developer, the code is as follows.
Create a object to store the resultset
Create a type as a table of he above object
Create a package to excute the SQL
Create the package body to excute the SQL
The code to excute and output the resultset
SELECT * FROM TABLE(ABC.TEST_RPT.get_report('','',''))
我假设您正在使用 Sql Plus 来执行此操作。首先,定义一个 Sql Plus refcursor。
变量 vcursor refcursor
接下来,执行匿名 pl/sql 块。请注意
declare
关键字。然后运行这个 sql plus 命令。
打印vcursor
print 不是 pl/sql
I assume you're using Sql Plus to execute this. First, define a Sql Plus refcursor.
variable vcursor refcursor
Next, execute an anonymous pl/sql block. Notice the
declare
keyword.Then run this sql plus command.
print vcursor
print is not pl/sql
您的引用光标变量是 rc。但随后你使用了
rc2
。将 rc2 更改为 rc 就可以了
Your ref cursor variable is
rc
. But then you userc2
.Change
rc2
torc
and it should work