【问题标题】:Error when calling an Oracle stored procedure though Java code通过 Java 代码调用 Oracle 存储过程时出错
【发布时间】:2015-12-12 11:49:30
【问题描述】:

我在 Java 应用程序中调用 PL/SQL 过程来更新数据库条目。

Connection connection = null;
CallableStatement preparedCall = null;
Integer result = 0;
preparedCall = connection.prepareCall("{ call ? := pkg_temp.update_data(?, ?)}");
preparedCall.registerOutParameter(1, OracleTypes.INTEGER);
preparedCall.setString(2, variable1);
preparedCall.setString(3, cariable2);
result = preparedCall.executeUpdate();

但我在 executeUpdate() 处收到以下错误

Caused by: java.sql.SQLException: ORA-06550: line 1, column 11:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
:= . ( @ % ; indicator
ORA-06550: line 1, column 51:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( ) , * % & - + / at mod remainder rem <an exponent (**)>
and or || multiset

我哪里做错了?

【问题讨论】:

    标签: java oracle stored-procedures jdbc callable-statement


    【解决方案1】:

    := 错误,返回参数的占位符必须列在 call 关键字(as documented in the JavaDocs)之前:

    connection.prepareCall("{?= call pkg_temp.update_data(?, ?)}");
    

    【讨论】:

    • 感谢您的建议。但是更改为此语法会产生此错误严重:java.sql.SQLException:ORA-06550:第 1 行,第 13 列:PLS-00382:表达式类型错误 ORA-06550:第 1 行,第 7 列:PL/SQL:语句忽略
    • 嗯,这是一个错误内部你的存储过程。您要么传递了错误的类型,要么您的过程依赖于邪恶的隐式数据类型转换。在任何一种情况下,如果没有看到程序的完整代码,就无法回答这个问题
    • 谢谢...我想我找到了问题所在。我的过程的返回类型是布尔值。但在这里我将它注册到整数。但是,将 out 参数注册到 OracleTypes.BOOLEAN 将不起作用。我该怎么办?
    猜你喜欢
    • 2014-11-23
    • 2014-08-16
    • 2023-03-05
    • 1970-01-01
    • 2011-12-27
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    相关资源
    最近更新 更多