returns setof refcursor表示您在调用时得到一个常规
ResultSet,其中每个“行”包含 另一个 ResultSet
getObject():
以下对我有用:
ResultSet rs = stmt.executeQuery("select * from usp_sel_article_initialdata_new1()");if (rs.next()){ // first result set returned Object o = rs.getObject(1); if (o instanceof ResultSet) { ResultSet rs1 = (ResultSet)o; while (rs1.next()) { int id = rs1.getInt(1); String name = rs1.getString(2); .... retrieve the other columns using the approriate getXXX() calls } }}if (rs.next()) { // process second ResultSet Object o = rs.getObject(1); if (o instanceof ResultSet) { ResultSet rs2 = (ResultSet)o; while (rs2.next()) { ...... } }}从内部
psql您也可以使用,
select * from usp_sel_article_initialdata_new1()您只需要在
FETCHALL以后使用即可。有关示例,请参见手册:http : //www.postgresql.org/docs/current/static/plpgsql-
cursors.html#AEN59018
postgres=> select * from usp_sel_article_initialdata_new1(); usp_sel_article_initialdata_new1---------------------------------- <unnamed portal 1> <unnamed portal 2>(2 rows)postgres=> fetch all from "<unnamed portal 1>"; ?column?---------- 1(1 row)postgres=> fetch all from "<unnamed portal 2>"; ?column?---------- 2(1 row)postgres=>
(我为上面的示例创建了一个虚拟函数,该函数仅返回一行包含
1第一个游标和
2第二个游标的值)
编辑 :
为了使其正常工作,它需要在事务内部运行。因此,必须关闭自动提交:
connection.setAutoCommit(false);



