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

帅比萌擦擦* 提交于 2019-11-26 18:28:39

问题


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

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.

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.

Can anyone help me, how to see the result.

.


回答1:


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

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

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

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

Unless P_CURSOR is declared as something unhelpful, maybe...




回答2:


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;


来源:https://stackoverflow.com/questions/8610495/how-to-see-refcursor-result-output-in-oracle-sql-developer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!