因业务复杂,SQL较为庞大,后改造为存储过程方式,传参,获取结果集,此处只显示存储过程的结构部分,也是最重要部分
CREATE OR REPLACE PACKAGE PKG_QUALITYCONTROL IS
TYPE retcursor IS REF CURSOR;
PROCEDURE GET_QUALITYCONTROL(v_encounterid in nvarchar2,
v_patientid in nvarchar2,
outcurse IN OUT retcursor);
END;
CREATE OR REPLACE PACKAGE BODY PKG_QUALITYCONTROL IS
PROCEDURE GET_QUALITYCONTROL(v_encounterid in nvarchar2,
v_patientid in nvarchar2,
outcurse IN OUT retcursor) IS
begin
OPEN outcurse FOR
select fm.formid,
fm.formtype,
fm.formname,
fm.formurl,
case
when exists (select 1
from form f
where f.states = 'N'
and f.formtype = fm.formtype
and f.encid = v_encounterid
and f.patientid = v_patientid) then
'暂存'
when exists (select 1
from form f
where f.states = 'Y'
and f.formtype = fm.formtype
and f.encid = v_encounterid
and f.patientid = v_patientid) then
'是'
else
'否'
end formtemp
from form_menu fm
where fm.formtype in ('Form1',
'Form2',
'Form3',
'Form4',
'Form5',
'Form6',
'Form7');
return;
end;
END;
上面两个SQL需要分开执行,一个是定义包,一个是定义包内容
java代码部分
public List<String[]> getFormMenuList(String encid, String patientid) throws ControllerException {
String me = getClass().getName() + ".getFormMenuList()";
List<String[]> ls = new ArrayList<String[]>();
Connection conn = null;
CallableStatement cstmt = null;
ResultSet rs = null;
String sql = "{call PKG_MANAGEJOBS.GET_QUALITYCONTROL(?, ?, ?)}";
try {
conn = getNisJdbcConnection();
cstmt = conn.prepareCall(sql);
cstmt.setString(1, encid);
cstmt.setString(2, patientid);
cstmt.registerOutParameter(3, oracle.jdbc.OracleTypes.CURSOR); //outcurse
cstmt.execute();
rs = (ResultSet) cstmt.getObject(3);
String[] array = null;
while (rs.next()) {
array = new String[7];
array[0] = rs.getString("formid");
array[1] = rs.getString("formtype");
array[2] = rs.getString("formname");
array[3] = rs.getString("formurl");
array[4] = rs.getString("formtemp");
ls.add(array);
}
} catch (Throwable e) {
throw new ControllerException("{0}:获取出院病人记录列表", new String[] { me }, e);
} finally {
closeConnection(conn, cstmt, rs);
}
return ls;
}