Creating Oracle Cursor using Java Program

后端 未结 1 1954
余生分开走
余生分开走 2021-01-29 06:19

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?

相关标签:
1条回答
  • 2021-01-29 07:04

    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 CURSORs

    Using 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 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 CURSORs are represented through the OracleRefCursor ODP.NET class.

    REF CURSORs 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.

    You need to create a stored procedure (or function) in the database that returns a cursor and then invoke that from your external application.

    0 讨论(0)
提交回复
热议问题