函数Demo

函数写法:
create or replace function f_getGoodsKuChun(gdId in varchar2)
return varchar2
as
v_gd_ismany varchar2(1);
v_gd_id_child varchar2(32);
v_amount_num number(12,2);
v_yw_num number(12,2); --业务数量
v_min_num number(12,2);
type refcur_type is REF CURSOR;
pcur refcur_type;
begin
v_gd_ismany := '0';
v_yw_num:=0;
v_amount_num:=0;

select t.GD_ISMANY into v_gd_ismany from t_ec_goods2 t where t.gd_id = gdId;

if v_gd_ismany='1' then --组合商品
open pcur for
select gd_id_child,cd_amount from t_ec_goodschild where gd_id=gdId order by cd_row;
loop
fetch pcur into v_gd_id_child,v_amount_num;
if pcur%notfound then
return v_min_num;
exit;
end if;

select sum(nvl(GD_SL,0) - nvl(frozen_amount,0) - nvl(out_amount,0)) into v_yw_num
from t_jxc_kc_factstock f,t_jxc_da_storeroom s
where f.gd_id=v_gd_id_child
and f.room_bm=s.room_bm and s.room_yn='Y';

v_amount_num := FLOOR(v_yw_num/v_amount_num);

if v_min_num is null then
v_min_num := v_amount_num;
else
if v_amount_num < v_min_num then
v_min_num := v_amount_num;
end if;
end if;

end loop;
Close pcur;
else --普通商品
select sum(nvl(f.GD_SL,0) - nvl(f.frozen_amount,0) - nvl(f.out_amount,0)) into v_min_num
from t_jxc_kc_factstock f,t_jxc_da_storeroom s
where f.room_bm = s.room_bm and s.room_yn = 'Y' and f.gd_id = gdId;
end if;


return v_min_num;


end f_getGoodsKuChun;

Java中调用函数的代码:
public int checkKucun(String gdId) {
Connection con = null;
CallableStatement ps = null;
int re = 0;
try {
con = commerceDao.getCurrentConnection();
// 调用存储过程
ps = con.prepareCall("{?=call f_getGoodsKuChun(?)}");
ps.registerOutParameter(1, Types.INTEGER);
ps.setString(2, gdId);

// 执行
ps.execute();
// 获得输出结果
re = ps.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
return re;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值