java - 调用 Returns 游标的存储函数
java - Calling Stored Function That Returns a Cursor
我有一个存储函数设置如下:
CREATE OR REPLACE PACKAGE PACKAGENAME IS
FUNCTION READ_FUNC(i_name IN VARCHAR2)
RETURN SYS_REFCURSOR;
END PACKAGENAME;
/
CREATE OR REPLACE PACKAGE BODY PACKAGENAME AS
FUNCTION
READ_FUNC(i_name IN VARCHAR2)
RETURN SYS_REFCURSOR
IS
cursor SYS_REFCURSOR;
BEGIN
//do stuff
RETURN cursor;
END READ_FUNC;
我正尝试按如下方式在 Java 中调用它,但我得到 not a valid function or procedure name
try(CallableStatement stmt = conn.prepareCall("call PACKAGENAME.READ_FUNC(?)")
{
stmt.setString(1, name);
ResultSet result = stmt.executeQuery();
// do stuff with result
}
它肯定存在,因为我可以desc PACKAGENAME
而且它有我的功能。我还能够调用其他程序。有谁知道我做错了什么吗?
尝试以下操作:
CallableStatement stmt = conn.prepareCall("{ ? = call PACKAGENAME.READ_FUNC(?) }");
stmt.registerOutParameter(1, OracleTypes.CURSOR);
stmt.setString(2, name);
我有一个存储函数设置如下:
CREATE OR REPLACE PACKAGE PACKAGENAME IS
FUNCTION READ_FUNC(i_name IN VARCHAR2)
RETURN SYS_REFCURSOR;
END PACKAGENAME;
/
CREATE OR REPLACE PACKAGE BODY PACKAGENAME AS
FUNCTION
READ_FUNC(i_name IN VARCHAR2)
RETURN SYS_REFCURSOR
IS
cursor SYS_REFCURSOR;
BEGIN
//do stuff
RETURN cursor;
END READ_FUNC;
我正尝试按如下方式在 Java 中调用它,但我得到 not a valid function or procedure name
try(CallableStatement stmt = conn.prepareCall("call PACKAGENAME.READ_FUNC(?)")
{
stmt.setString(1, name);
ResultSet result = stmt.executeQuery();
// do stuff with result
}
它肯定存在,因为我可以desc PACKAGENAME
而且它有我的功能。我还能够调用其他程序。有谁知道我做错了什么吗?
尝试以下操作:
CallableStatement stmt = conn.prepareCall("{ ? = call PACKAGENAME.READ_FUNC(?) }");
stmt.registerOutParameter(1, OracleTypes.CURSOR);
stmt.setString(2, name);