如何使用Spring SimpleJdbcCall调用PostgreSQL存储过程并从refcursor中获取数据

时间:2020-01-09 09:25:51

标签: postgresql stored-procedures spring-jdbc simplejdbccall

我在PostgreSQL中有一个存储过程,该存储过程返回一个 refcursor ,我想使用Spring Jdbc SimpleJdbcCall对其进行调用。

过程代码如下:

CREATE OR REPLACE FUNCTION show_emps() RETURNS refcursor AS $$
DECLARE
  ref refcursor;                                     -- Declare a cursor variable
BEGIN
  OPEN ref FOR SELECT emp_id, first_name FROM emp;   -- Open a cursor
  RETURN ref;                                                      
END;
$$ LANGUAGE plpgsql;

谁能帮助我使用代码来调用此过程并使用SimpleJdbcCall类获取其数据。 我正在使用以下代码进行通话,但无法正常工作:

SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate);
jdbcCall.withProcedureName("show_emps");

Map<String, Object> result = jdbcCall.execute();

0 个答案:

没有答案
相关问题