Search code examples
oracle-databaseplsqlcursorprocedure

How to pass a Ref Cursor as an argument to a Stored Procedure?


How to pass a Ref Cursor as an argument to a Stored Procedure?

I am trying to call a stored procedure that expects cursor as a parameter.The Cursor used in the stored procedure as out parameter. Both the stored procedure and cursor are defined in a package.

How to call the stored procedure by passing the cursor? Please explain with an example

This how the procedure and cursor are written.

PACKAGE company
IS

/* Define the REF CURSOR type. */
TYPE curvar_type IS REF CURSOR RETURN company%ROWTYPE;

/* Stored Procedure Impl */
PROCEDURE open_company (curvar_out OUT company.curvar_type) IS
BEGIN
   ...
END;
END package;

Thanks in advance.


Solution

  • The procedure's parameter is an out parameter - you do not need to pass a cursor to the procedure as the effect of the procedure is to pass a cursor out (not in).

    So, you can get the outputted cursor like this:

    DECLARE
      cur COMPANY.CURVAR_TYPE;
    BEGIN
      company.open_company( cur );
      -- do something with the cursor.
    END;
    /