作为 SYS_REFCURSOR 参数传递的内容
这里我在 Oracle 中有一个存储过程:
CREATE OR REPLACE PROCEDURE StP_COMPS
IS
CV_1 SYS_REFCURSOR;
BEGIN
OPEN CV_1 FOR SELECT * FROM COMPUTERS;
END;
当我执行像 EXEC SP_COMPS 这样的过程时,我没有得到任何错误,SQL Developer 只显示“任意块已完成”。然后我将过程更改为 a
CREATE OR REPLACE PROCEDURE SP_COMPS
(cv_1 OUT SYS_REFCURSOR)
IS
BEGIN
OPEN CV_1 FOR SELECT * FROM COMPUTERS;
END;
,当我执行时,我收到错误,指出参数类型的数量错误。我很好奇如果它只是一个输出参数,我可以将什么作为参数发送给过程。我想获取过程内运行的查询的结果集。我在这里做错了什么?
PS 当我尝试通过右键单击该过程并选择“运行”来运行该过程时,我得到:
DECLARE
CV_2 sys_refcursor;
BEGIN
SP_COMPS(
CV_2 => CV_2
);
:CV_2 := CV_2; -- <--Can't understand this part
END;
Here I have a stored procedure in Oracle:
CREATE OR REPLACE PROCEDURE StP_COMPS
IS
CV_1 SYS_REFCURSOR;
BEGIN
OPEN CV_1 FOR SELECT * FROM COMPUTERS;
END;
When I execute the procedure like EXEC SP_COMPS I get no error, the SQL Developer just shows "ananymous block completed". Then I change the procedure to a
CREATE OR REPLACE PROCEDURE SP_COMPS
(cv_1 OUT SYS_REFCURSOR)
IS
BEGIN
OPEN CV_1 FOR SELECT * FROM COMPUTERS;
END;
and when I execute I get error stating that the number of type of the arguments are wrong. I'm very curious what I could send as an argument to the procedure if it's just an output parameter. I want to get the result set of the query run inside the procedure. What am I doing wrong here?
P.S. When I try to run the procedure by right clicking the procedure and selecting Run I get:
DECLARE
CV_2 sys_refcursor;
BEGIN
SP_COMPS(
CV_2 => CV_2
);
:CV_2 := CV_2; -- <--Can't understand this part
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有一个变量,你应该执行如下过程:
更新(OP更新后):这是一个简单的测试模板。如此处所述:测试 Oracle 存储过程的最简单方法 ,只需运行该代码,然后选择 ref_cursor 作为 cv2 变量的类型。
You have a variable, you should execute the procedure like:
UPDATE(after OP update): That's a simple template for testing. As explained here: Easiest method to test an Oracle Stored Procedure, just run that code, and select ref_cursor as type of cv2 variable.