I wanted to create Oracle Cursor with the help of Java Code. I tried searching on the Internet but I didn\'t find anything. Can we create Cursor using Java code?
You cannot create a cursor using Java code.
A cursor is a reference (pointer) to a data structure internal to the database representing a query and a corresponding set of results - creating the pointer outside of the database would be meaningless.
From the Oracle Documentation:
Introduction to
REF CURSOR
sUsing
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, aREF CURSOR
is a pointer or a handle to a result set on the database.REF CURSOR
s are represented through theOracleRefCursor
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 theREF CURSOR
in order to access it.A
REF CURSOR
involves an additional database round-trip. While theREF CURSOR
is returned to the client, the actual data is not returned until the client opens theREF 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 theREF CURSOR
is read-only. You cannot update the database by using aREF CURSOR
.A
REF CURSOR
is not backward scrollable. The data represented by theREF CURSOR
is accessed in a forward-only, serial manner. You cannot position a record pointer inside theREF CURSOR
to point to random records in the result set.A
REF CURSOR
is a PL/SQL data type. You create and return aREF CURSOR
inside a PL/SQL code block.
You need to create a stored procedure (or function) in the database that returns a cursor and then invoke that from your external application.