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 CURSORsUsing
REF CURSORs is one of the most powerful, flexible, and scalable ways to return query results from an Oracle Database to a client application.
REF CURSORis a PL/SQL data type whose value is the memory address of a query work area on the database. In essence, aREF CURSORis a pointer or a handle to a result set on the database.REF CURSORs are represented through theOracleRefCursorODP.NET class.
REF CURSORs have the following characteristics:
A
REF CURSORrefers to a memory address on the database. Therefore, the client must be connected to the database during the lifetime of theREF CURSORin order to access it.A
REF CURSORinvolves an additional database round-trip. While theREF CURSORis returned to the client, the actual data is not returned until the client opens theREF CURSORand requests the data. Note that data is not be retrieved until the user attempts to read it.A
REF CURSORis not updatable. The result set represented by theREF CURSORis read-only. You cannot update the database by using aREF CURSOR.A
REF CURSORis not backward scrollable. The data represented by theREF CURSORis accessed in a forward-only, serial manner. You cannot position a record pointer inside theREF CURSORto point to random records in the result set.A
REF CURSORis a PL/SQL data type. You create and return aREF CURSORinside 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.