here is a working example, declare the refcursor then assign the value by calling you proc in an anonymous block.
then you print it
var x REFCURSOR ;
declare
/*a no cleanup procedure*/
procedure GetMeMyRefCursor(outter out nocopy sys_refcursor)
as
begin
open outter for
select level
from dual
connect by level <= 5;
end GetMeMyRefCursor;
begin
GetMeMyRefCursor(:x);
/*note you pass in the refcursor you created via the :X*/
end ;
/
print x;
/*now print it*/
/*LEVEL
----------------------
1
2
3
4
5*/
based on comment:
now using your comment, you are having an issue with IN/OUT params and not with the print (didn't read the title just the question and the other response)
this works: (based on your code)
create or replace
PROCEDURE GET_PROJECT_DRF_HISTORY
( projectId IN NUMBER,
resultset_out OUT sys_refcursor
) AS
BEGIN
OPEN resultset_out for
SELECT level from dual connect by level <= projectId;
/* DBMS_OUTPUT.PUT_LINE(resultset_out);*/
END GET_PROJECT_DRF_HISTORY;
/
var results REFCURSOR;
--this needs to be REFCURSOR (at least in 10g and 11i)
exec GET_PROJECT_DRF_HISTORY(5, :results);
print results;
/
You can also debug packages and procedures directly from SQL Developer (this can be a real life saver)
if you want to debug in SQL Developer it is really easy:
in the connections->your schema here-->procedures -> GET_PROJECT_DRF_HISTORY right click and 'Compile for debug'. Then in the procedure place a break point in it, then right click and 'debug' it (this will create an anonymous block -- see below -- where you can put in your values and such)
DECLARE
PROJECTID NUMBER;
RESULTSET_OUT sys_refcursor;
BEGIN
PROJECTID := NULL;
GET_PROJECT_DRF_HISTORY(
PROJECTID => PROJECTID,
RESULTSET_OUT => RESULTSET_OUT
);
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('RESULTSET_OUT = ' || RESULTSET_OUT);
END;
(http://www.oracle.com/technetwork/developer-tools/sql-developer/sqldeveloperwhitepaper-v151-130908.pdf page 11)
otherwise, the error doesn't look as it should appear if you are doing this all from Developer.
But what I really think is happening is your VAR is incorrect and thus it doesn't exists!
variable results sys_refcursor;
Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
BINARY_FLOAT | BINARY_DOUBLE ] ]
so, going from my initial example "var x REFCURSOR ;" should work