从 Spring JAVA 中的 Oracle PLSQL 函数获取结果集时出错

Error in fetching resultset from oracle PLSQL function in Spring JAVA

我是 spring 启动开发和 java 的新手。

我在这里尝试借助 simpleJdbcCall.executeFunction 方法从 spring 引导调用 Oracle PLSQL 函数。我的 plsql 函数返回单个 table 行。在 java 中,我试图将函数的 result/output 存储在 Map 数据类型中,但是每当我尝试 运行 应用程序时,我都会遇到如下所述的错误

PLSQL 函数:

CREATE TABLE test.account1 (
 account_id INT,
 name       VARCHAR2(20)
);

INSERT INTO test.account1 VALUES ( 1, 'Bob' );
INSERT INTO test.account1 VALUES ( 2, 'Nob' );

create or replace function test.get_accounts
(Acc_id in Account1.account_id%Type)
return account1%rowtype
as
l_cust_record account1%rowtype;
begin
select * into l_cust_record from account1
where account_id=Acc_id;
return(l_cust_record);
end;
/

Java方法:

@SuppressWarnings("unchecked")
public void testFunctionTablerow(){
    this.jdbcTemplate =new JdbcTemplate(datasource);
    System.out.println("1");
    simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withFunctionName("get_accounts");
    System.out.println("2");
    SqlParameterSource in= new MapSqlParameterSource().addValue("Acc_id", 1);
    System.out.println("3");
    //Map<String, Object> out = simpleJdbcCall.executeFunction(Map.class, in);
    Map<String, Object> out= simpleJdbcCall.executeFunction(Map.class, in);
    System.out.println(out);

}

错误:

2018-07-12 12:18:34.620  INFO 1560 --- [nio-8000-exec-2] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2018-07-12 12:18:34.669  INFO 1560 --- [nio-8000-exec-2] o.s.jdbc.support.SQLErrorCodesFactory    : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]

你能帮帮我吗?让我知道当函数返回整行时,将 plsql 函数输出的值存储在 java 中的正确方法是什么。如果您知道调用此类函数的任何其他方法 returns 复杂输出,请分享。

谢谢

您可以尝试调用 returningResultSet 方法,如下所述:

Calling Oracle procedure that returns rows using SimpleJdbcCall in Spring