oracle带返回值储存过程

阅读更多
存储过程
create or replace procedure sp_pro_order(spName in nvarchar2,spAddress in nvarchar2,spId out number) is
begin
INSERT INTO ORDER_MC(ID,NAME,ADDRESS,CREATETIME)  values(order_id.nextval,spName,spAddress,SYSDATE);
select order_id.currval into spId from dual;
end sp_pro_order;



java 代码调用
  Connection conn=super.getConn(); 
  try {
   String sql="{call sp_pro_order(?,?,?)} ";
   CallableStatement cs=conn.prepareCall(sql);
   cs.setString(1, om.getName());
   cs.setString(2, om.getAddress());
   cs.registerOutParameter(3, oracle.jdbc.OracleTypes.NUMBER);//返回值类型
   cs.execute();
   int id=cs.getInt(3);//3为返回值位置

你可能感兴趣的:(oracle带返回值储存过程)