pl⼀sql 存储过程调用 带cursor输出参数

2025-05-13 13:09:23
推荐回答(1个)
回答(1):

1.创建表T_MONITOR_DEVICE
创建后的表结构

2.创建存储过程

create or replace procedure ProcTestNew(v_monitordeviceid in number,curdata out sys_refcursor )
As

begin

open curdata for
select ID, IP,PORT from T_MONITOR_DEVICE where id=v_monitordeviceid;--带参数测试
-- select ID, IP,PORT from T_MONITOR_DEVICE;
end ProcTestNew;

二.java程序中调用

public void TestProc()
{
Connection conn=null;
ResultSet rs=null;
try {
//this.getSession()为hibernate中的Session对象
conn = SessionFactoryUtils.getDataSource(this.getSession().getSessionFactory()).getConnection();
CallableStatement proc = conn.prepareCall("{call ProcTestNew(?,?) }");
BigDecimal b1 = new BigDecimal(1176);
proc.setBigDecimal(1, b1);
proc.registerOutParameter(2, OracleTypes.CURSOR);