Question: I´ve looked all over for this and can´t seem to find an answer. If this has already been posted, please point me in that direction.

I have an Oracle Stored procedure that I have to invoke from Java. This SP ask´s for a REFCURSOR type as an IN parameter (as in I have to SEND a REFCURSOR to it).

I know how to receive a REFCURSOR as a response from an SP (using a callablestatement and Stmt.registerOutParameter(3, OracleTypes.CURSOR); for example. This is NOT what I want. 

I can´t modify the SP (sadly enough...)

I need sample code to:

-create the REFCURSOR in Java

-Send it as a parameter to the SP.

Thx a lot for any help provided.

Answer: 
From the [Oracle Documentation](https://docs.oracle.com/cd/E11882_01/appdev.112/e10767/procedures_plsql.htm#TDPNG60035):

> 
> Introduction to `REF CURSOR`s
> =============================
> 
> 
> Using `REF CURSOR`s is one of the most powerful, flexible, and scalable ways to return query results from an Oracle Database to a client application.
> 
> 
> `REF CURSOR` is a PL/SQL data type whose value is the memory address of a query work area on the database. In essence, a `REF CURSOR` is a pointer or a handle to a result set on the database. `REF CURSOR`s are represented through the `OracleRefCursor` ODP.NET class.
> 
> 
> `REF CURSOR`s have the following characteristics:
> 
> 
> * A `REF CURSOR` refers to a memory address on the database. Therefore, the client must be connected to the database during the lifetime of the `REF CURSOR` in order to access it.
> * A `REF CURSOR` involves an additional database round-trip. While the `REF CURSOR` is returned to the client, the actual data is not returned until the client opens the `REF CURSOR` and requests the data. Note that data is not be retrieved until the user attempts to read it.
> * A `REF CURSOR` is not updatable. The result set represented by the `REF CURSOR` is read-only. You cannot update the database by using a `REF CURSOR`.
> * A `REF CURSOR` is not backward scrollable. The data represented by the `REF CURSOR` is accessed in a forward-only, serial manner. You cannot position a record pointer inside the `REF CURSOR` to point to random records in the result set.
> * A `REF CURSOR` is a PL/SQL data type. You create and return a `REF CURSOR` inside a PL/SQL code block.
> 
> 
> 

So, you cannot create a `REF CURSOR` in Java; instead you will need to create it in the database, pass it to your Java application and then pass it back to the procedure you are calling (or else do it all in the database).
REF Cursor is a Oracle type and cannot be created outside of PL/Sql. I think what you want is a cursor type in java to make a call to a stored procedure that contains a ref cursor type. The following link will bring you to Oracle's Oracle8i JDBC Developer's Guide and Reference documentation. It contains a sample of how to call a stored procedure with a cursor (REF Cursor) parameter. The specific line is:

```
call.registerOutParameter (1, OracleTypes.CURSOR);

```

I don't know if you're using JDBC, but it may apply to your java implementation as well.