我有以下PL / SQL块,当我通过匿名块从PL / SQL开发人员调用它时,它可以正常工作。
CREATE OR REPLACE FUNCTION getuserlist
RETURN SYS_REFCURSOR
IS userscursor SYS_REFCURSOR;
BEGIN
OPEN userscursor FOR
SELECT USER_ID
, USER_NAME
FROM TEST_USERS;
RETURN userscursor;
END;
但是,每当我从我的java应用程序(Web服务)调用它时,它都会抛出以下错误:
ORA-06550:第1行,第28栏: PLS-00103:遇到符号";"期待以下之一:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
The symbol "exit" was substituted for ";" to continue.
这是我的java代码片段:
String userListSQL = "{ ? = call GETUSERLIST(); }";
CallableStatement statement = conn.prepareCall(userListSQL);
statement.registerOutParameter(1, OracleTypes.CURSOR); //this is the line it throws an error
statement.execute();
resultSet = ((OracleCallableStatement)statement).getCursor(1);
任何帮助表示赞赏!
答案 0 :(得分:0)
您确定这是如何从存储过程调用获取结果集的正确方法吗?
String userListSQL = "{ ? = call GETUSERLIST(); }";
我认为如果你使用JDBC兼容的驱动程序,这应该可行:
PreparedStatement statement = conn.prepareStatement("CALL GETUSERLIST()");
resultset = statement.executeQuery();