我已经查遍了这个问题,但似乎找不到答案。如果此内容已发布,请指出该方向。
我有一个必须从 Java 调用的 Oracle 存储过程。此 SP 要求 REFCURSOR 类型作为 IN 参数(如我必须向其发送 REFCURSOR)。
我知道如何接收 REFCURSOR 作为来自 SP 的响应(使用 callablestatement 和 Stmt.registerOutParameter(3, OracleTypes.CURSOR);例如。这不是我想要的。
我无法修改 SP(很遗憾......)
我需要示例代码:
-在 Java 中创建 REFCURSOR
-将其作为参数发送给 SP。
非常感谢您提供的任何帮助。
最佳答案
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.
因此,您无法在 Java 中创建REF CURSOR
;相反,您需要在数据库中创建它,将其传递给 Java 应用程序,然后将其传递回您正在调用的过程(或者全部在数据库中完成)。
关于java - 从 Java 将 REFCURSOR 类型变量发送到 Oracle 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43710288/