业务场景:
需要在代码中调用有返回值的存储过程,返回值类型为动态游标,数据库为金仓。
1 定义存储过程:
CREATE OR REPLACE PROCEDURE pro_业务_pld(
p_orgId varchar,
p_pld NUMERIC,
p_reCursor OUT refcursor
) as
v_sql VARCHAR2(4000);
begin
open p_reCursor for
SELECT 字段 FROM 表;
END;
2 Java代码:
CallableStatement callableStatement = connection.prepareCall("{ call pro_业务_pld(?, ?, ?) }");
callableStatement.setString(1, pOrgId);
callableStatement.setDouble(2, pPld);
callableStatement.registerOutParameter(3, java.sql.Types.REF_CURSOR);
callableStatement.execute();
// 获取返回结果集
ResultSet resultSet = (ResultSet) callableStatement.getObject(3);