1. 创建oracle package body
2. Example for calling procedure:
3. Example for calling function:
CREATE OR REPLACE PACKAGE pkg_test as
function testFucGet(ID number) return varchar2;
Procedure testProGet(ID number,
return_name out varchar2
);
end pkg_test;2. Example for calling procedure:
try {
conn.setAutoCommit(false);
CallableStatement proc = conn
.prepareCall("{call pkg_test.testProGet(?,?)}");
proc.setInt(1, 1);
proc.registerOutParameter(2, OracleTypes.VARCHAR);
proc.execute();
ResultSet rs = (ResultSet) proc.getObject(2);
while (rs.next()) {
System.out.println(rs.getString(2));
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}3. Example for calling function:
try {
conn.setAutoCommit(false);
CallableStatement proc = conn
.prepareCall("{call ? := pkg_test.testFucGet(?)}");
proc.setInt(2, 0);
proc.registerOutParameter(1, OracleTypes.VARCHAR);
proc.execute();
ResultSet rs = (ResultSet) proc.getObject(1);
while (rs.next()) {
System.out.println(rs.getString(2));
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
2439

被折叠的 条评论
为什么被折叠?



