create or replace procedure PRC_WZ_DACK
(
as_lyxh in varchar2,
as_lylx in number,
as_daxh in varchar2,
as_syks in varchar2,
as_syry in varchar2,
as_kfjb in number,
as_fsdm in number,
as_ckrq date,
as_jbr in varchar2,
as_zdr in varchar2,
as_djno out varchar2)
is
cursor userRows is select * from wz_daxx where daxh = as_daxh;
p_ckxh varchar2(10);
p_cwpxh varchar2(10);
p_djno varchar2(20);
ls_ckxh varchar2(10);
errcode number; --异常序号
BEGIN
SELECT fn_getxh('WZ_CKD') INTO p_ckxh FROM DUAL;
SELECT fn_getxh('WZ_CKMX') INTO p_cwpxh FROM DUAL;
SELECT fn_getdjno('CKD') INTO p_djno FROM DUAL;
--删除出库单以及出库单明细
IF as_lylx = 0 THEN
select DJXH INTO ls_ckxh from WZ_DAJY WHERE ZKPB = 0 AND JYXH = as_lyxh;
ELSE
select DJXH INTO ls_ckxh from WZ_DABZ WHERE ZKPB = 0 AND BZXH = as_lyxh;
END IF;
IF ls_ckxh IS NOT NULL THEN
delete from wz_ckd where ckxh = ls_ckxh;
delete from wz_ckmx where ckxh = ls_ckxh;
END IF;
commit;
for userRow in userRows loop
--出库单据
INSERT INTO WZ_CKD(ckxh,djno,fsdm,ckrq,
jbr,syks,syry,djje,wzsm,kjqj,
zdr,zdrq,jzr,jzrq,jzpb,kfjb,zfpb)
VALUES(p_ckxh,p_djno,as_fsdm,as_ckrq,
as_jbr,as_syks,as_syry,userRow.Dj,userRow.Wzsm,null,
as_zdr,sysdate,NULL,NULL,0,as_kfjb,0);
--出库明细
INSERT INTO WZ_CKMX(cwpxh,ckxh,wpxh,wpdm,wpmc,kcxh,pp,
gg,dj,sl,dw,je,
syks,syry,lydj,kfjb,zfpb)
VALUES(p_cwpxh,p_ckxh,userRow.Wpxh,userRow.Wpdm,userRow.Wpmc,NULL,userRow.Pp,
userRow.Gg,userRow.Dj,1,userRow.Dw,userRow.Dj,
as_syks,as_syry,userRow.Rkxh,as_kfjb,0);
--暂时代码 UPDATE WZ_DAXX SET CKXH = p_ckxh WHERE DAXH = as_daxh;
IF as_lylx = 0 THEN
UPDATE WZ_DAJY SET DJXH = p_ckxh, ZKPB = 0 where JYXH = as_lyxh;
ELSE
UPDATE WZ_DABZ SET DJXH = p_ckxh, ZKPB = 0 where BZXH = as_lyxh;
END IF;
END LOOP;
as_djno := p_djno;
Exception
when others then --在有异常的情况下
errcode := sqlcode;
rollback;
return;
as_djno := errcode;
END PRC_WZ_DACK;
仔细看下。