【问题标题】:How do I write StoredProcedure sub-classes to call Oracle functions?如何编写 StoredProcedure 子类来调用 Oracle 函数?
【发布时间】:2010-10-12 23:46:09
【问题描述】:

我编写了以下 Spring JDBC API StoredProcedure 子类:

class GetLdapPropertiesStoredProcedure extends StoredProcedure {

protected GetLdapPropertiesStoredProcedure(JdbcTemplate jdbcTemplate) {
    super(jdbcTemplate, "get_ldap_properties");
    setFunction(true);
    declareParameter(new SqlReturnResultSet("rs", new ProductPropertiesMapper()));
    declareParameter(new SqlParameter("in_ldap_code", Types.VARCHAR));
    compile();
}

public Properties execute(String productCode) {
    HashMap input = new HashMap();
    input.put("in_ldap_code", productCode);

    Map results = execute(input);

    Collection<Map.Entry<Object,Object>> entries = (Collection<Map.Entry<Object,Object>>) results.get("rs");
    Properties properties = new Properties();
    properties.entrySet().addAll(entries);
    return properties;
}

}

调用以下Oracle函数:

FUNCTION get_ldap_properties (
in_ldap_code   IN VARCHAR2
)
RETURN rowset;

但是,当我调用上述代码时,我得到以下 Oracle 异常:

java.sql.SQLException: ORA-06550: line 1, column 13:
PLS-00306: wrong number or types of arguments in call to 'GET_LDAP_PROPERTIES'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

谁能看看我做错了什么?

【问题讨论】:

    标签: java oracle spring jdbc


    【解决方案1】:

    这是您将获得的函数调用语句(即setFunction(true)) :

    { ? = 调用 get_ldap_properties(?) }
    

    所以你需要为返回值添加一个先出参数。试试这个:

    setFunction(true);
    
    // 返回值参数必须是你声明的第一个参数。
    declareParameter(new SqlOutParameter("RETURN_VALUE", OracleTypes.CURSOR, new ProductPropertiesMapper()));
    

    编辑:根据 Thomas Risberg 在 Spring 社区论坛上的 answer,修复了使用 Oracle 时处理函数返回值行集的语法。

    【讨论】:

    • 感谢您的回答,但这并没有告诉我如何修复行集的东西。这回答了这个问题:forum.springframework.org/showthread.php?p=231407
    • 这里有两件事:添加一个 SqlOutParamater 作为 first 参数并使用好的类型。我不知道我为什么要写 Types.VARCHAR ......我会修复答案。
    猜你喜欢
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多