ibatis调用Oracle中的function

2014-11-24 15:10:08 · 作者: · 浏览: 0

ibatis调用 Oracle中的function
先做这样的假设,学生的学号和姓名可以唯一确定一个学生。
Oracle存储过程
create or replace function get_stu_birth(vid varchar,vname varchar) return date is
vbirth date; www.2cto.com
n number;
begin
select count(*),birth into n,pbirth from student where id = vid and name = vname;
if n>0 then
vbirth:=pbirth;
else
null;
end if;
return vbirth;
end;
StudentSqlMapper.xml
www.2cto.com
{ = call get_stu_birth( , ) }
]]>
Student.java
Map mapIn = new HashMap();
mapIn.put("vid", "100"); www.2cto.com
mapIn.put("vname", "xy");
mapIn.put("vbirth", "");
baseDao.selectObject("studentMapper.stuproc", mapIn);
Date birth = DateUtil.toDate(mapIn.get("vbirth").substring(0, mapIn.get("vbirth").length() - 2), "yyyy-mm-dd hh24:mi:ss");
在执行完这句话之后baseDao.selectObject("studentMapper.stuproc", mapIn),mapIn.get("vbirth")的值已经被装进去了。
格式如2012-1-1 12:12:12.0,所以要处理一下。