Function定义

来源:互联网 发布:五彩十二花神杯淘宝 编辑:程序博客网 时间:2024/04/29 23:57

 1.Function声明:

create or replace function getValueFunc(num NVARCHAR2)
return NVARCHAR2 is
       fnameRet NVARCHAR2(100);
begin
     select fname into fnameRet from t_afl_bd_custrptitem where fnumber = num;
     return fnameRet;    
end;

 

2.测试:

select getValueFunc('0500124') from dual

 

3.JDBC调用:

  Connection con = null;
  CallableStatement cs = null;
  try {
   con = ConnectionFacatory.getCon();
   cs = con.prepareCall("{? = call getValueFunc(?)}");
   cs.registerOutParameter(1, Types.VARCHAR);
   cs.setString(2, "0500124");
   cs.execute();
   String retValue = cs.getString(1);
   System.out.println(retValue);
  } catch (SQLException e) {
   throw new BOSException(e);
  } finally {
   try {
    cs.close();
    con.close();
   } catch (SQLException e) {
    throw new BOSException(e);
   }
  }

2009-10-20

原创粉丝点击