如何在 Oracle SQL Developer 中查看 refcursor 结果/输出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8610495/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:47:43  来源:igfitidea点击:

How to see refcursor result/output in Oracle SQL Developer?

oracleplsqloracle10goracle-sqldeveloperref-cursor

提问by Prabin Yovan

Possible Duplicate:
Best way/tool to get the results from an oracle package procedure
Oracle SQL Developer: Show REFCURSOR Results in Grid?

可能的重复:
从 oracle 包过程中获取结果的最佳方法/工具
Oracle SQL Developer:在网格中显示 REFCURSOR 结果?

I am new to Oracle SQL Developer. I am using Oracle SQL Developer Version 3.0. I was trying to test my SP using the following query.

我是 Oracle SQL Developer 的新手。我使用的是 Oracle SQL Developer 3.0 版。我试图使用以下查询来测试我的 SP。

DECLARE
  type output_cursor is ref cursor;
  P_CURSOR output_cursor;
BEGIN
  P_CURSOR := NULL;
  myPackage.mySPTest (  P_NOTIFICATION_ID => 1975357,P_CURSOR => P_CURSOR) ;
END;

When I ran the above query in my Oracle SQL Developer, I am getting a message 'anonymus block completed' and its not showing any result.

当我在 Oracle SQL Developer 中运行上述查询时,我收到一条消息“匿名块已完成”,但没有显示任何结果。

Can anyone help me, how to see the result.

任何人都可以帮助我,如何看到结果。

.

.

回答by Alex Poole

You can use a bind variable declared in SQL Developer to hold and show the results:

您可以使用在 SQL Developer 中声明的绑定变量来保存和显示结果:

var r refcursor;
exec myPackage.mySPTest(P_NOTIFICATION_ID => 1975357, P_CURSOR => :r);
print r;

execis shorthand for an anonymous block so this is equivalent to:

exec是匿名块的简写,所以这相当于:

var r refcursor;
begin
    myPackage.mySPTest(P_NOTIFICATION_ID => 1975357, P_CURSOR => :r);
end;
/
print r;

Unless P_CURSORis declared as something unhelpful, maybe...

除非P_CURSOR被宣布为无用的东西,否则也许......

回答by Emmanuel N

To view your cursor results you need to loop through your cursor and print values. You need to know column names for what your cursor is returning. You can do something like:

要查看光标结果,您需要遍历光标并打印值。您需要知道光标返回的列名。您可以执行以下操作:

DECLARE
   type output_cursor is ref cursor;
   P_CURSOR output_cursor;
BEGIN
   P_CURSOR := NULL;
   DOCTORS_APP.get_reminders (  P_NOTIFICATION_ID => 1975357,P_CURSOR => P_CURSOR) ;
   //replace Column1 and Column2 with actual column names
   FOR CUR_VAL in P_CURSOR LOOP
        DBMS_OUTPUT.PUT_LINE(CUR_VAL.Column1||' '||CUR_VAL.Column2);
   END LOOP;
 END;