我的存储功能设置如下:
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
并且它具有我的功能。我也可以打电话给其他程序。有谁知道我做错了什么?
答案 0 :(得分:3)
尝试以下方法:
CallableStatement stmt = conn.prepareCall("{ ? = call PACKAGENAME.READ_FUNC(?) }");
stmt.registerOutParameter(1, OracleTypes.CURSOR);
stmt.setString(2, name);