作为 SYS_REFCURSOR 参数传递的内容

发布于 2024-12-18 11:48:57 字数 701 浏览 3 评论 0原文

这里我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笔落惊风雨 2024-12-25 11:48:57

你有一个变量,你应该执行如下过程:

DECLARE
  CV_1 SYS_REFCURSOR;
BEGIN
  SP_COMPS(CV_1);
  --use cv_1
END;

更新(OP更新后):这是一个简单的测试模板。如此处所述:测试 Oracle 存储过程的最简单方法 ,只需运行该代码,然后选择 ref_cursor 作为 cv2 变量的类型。

You have a variable, you should execute the procedure like:

DECLARE
  CV_1 SYS_REFCURSOR;
BEGIN
  SP_COMPS(CV_1);
  --use cv_1
END;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文