Oracle 执行JOB程序自动存储数据
//执行定时任务
DECLARE
JOB NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT(job,'CUX_FinishedProcedure;',SYSDATE,'SYSDATE+30/(60*24*60)');
END;
//执行存储过程
CREATE OR REPLACE PROCEDURE CUX_FinishedProcedure IS
vExist NUMBER(30);
isExist NUMBER(30);
VERRINFO VARCHAR(100);
BEGIN
FOR I IN (
select mfg.mfgordername,co.mfgorderid,en.enterprisename,sum( co.qty2)as cuxboxqty ,sum (co.qty) qty,
cum.afterconversionuom,cum.beforeconversionuom,
try.cuxtrayname,mfg.ponumber,mfg.cuxcuzzhh,co.cuxlgort,co.cuxtrayid
from container co
left join mfgorder mfg on mfg.mfgorderid=co.mfgorderid
left join currentstatus cu on co.currentstatusid=cu.currentstatusid
left join enterprise en on en.enterpriseid=mfg.cuxenterpriseid
left join product pr on pr.productid=mfg.productid or pr.productbaseid=mfg.productbaseid
left join productbase prb on prb.productbaseid=pr.productbaseid
left join cuxmfgorderspec cum on cum.specid=cu.specid and cum.mfgorderid=co.mfgorderid
left join producttype prt on pr.producttypeid=prt.producttypeid
left join spec sp on sp.specid=cu.specid
left join cuxtray try on try.cuxtrayid=co.cuxtrayid
where prt.producttypename='ZFER' and co.cuxproductlotstatus in (unistr('\5408\683C'),unistr('\514D\68C0'))
and CO.CUXISPUTSTORAGE is null and sp.cuxisbeginspec='E' and try.status=unistr('\5DF2\7EC4\76D8') AND CO.CUXISVIRTUAL=0
group by mfg.mfgordername,en.enterprisename,cum.afterconversionuom,cum.beforeconversionuom,
try.cuxtrayname,mfg.ponumber,mfg.cuxcuzzhh,co.cuxlgort,co.mfgorderid,co.cuxtrayid
) LOOP
SELECT COUNT(1) INTO isExist FROM CONTAINER CON
LEFT JOIN MFGORDER MFGO ON MFGO.MFGORDERID=CON.MFGORDERID
LEFT JOIN CUXTRAY CTRY ON CTRY.CUXTRAYID=CON.CUXTRAYID WHERE CTRY.CUXTRAYNAME=I.CUXTRAYNAME AND CON.CUXPRODUCTLOTSTATUS NOT IN( unistr('\5408\683C'),unistr('\514D\68C0')) --OR CON.CUXPRODUCTLOTSTATUS IS NULL
AND MFGO.MFGORDERNAME=I.MFGORDERNAME;
IF isExist >0 THEN CONTINUE;
ELSE
SELECT COUNT(1) INTO vExist FROM CUX_FinishedProduct C WHERE C.CUXTRAY = I.CUXTRAYNAME AND C.MFGORDER=I.MFGORDERNAME AND C.CUXSTATUS='0';
IF vExist > 0 THEN CONTINUE;
ELSE
UPDATE CONTAINER CON SET CON.CUXISPUTSTORAGE='1' WHERE con.mfgorderid =I.Mfgorderid and con.cuxtrayid=I.Cuxtrayid;
COMMIT;
INSERT INTO CUX_FinishedProduct(
Guid,
MfgOrder,
Enterprise,
CUXBoxQty,
CUXBeforeConversionUOM,
CUXTray,
CUXStorageLocation,
CUXAfterConversionUOM,
CUXInQty,
CUXZPODAT,
CUXZZHH,
CUXStatus,
CUXCreateTime,
CUXCreateUser
) VALUES(
SYS_GUID(),
I.MFGORDERNAME,
I.ENTERPRISENAME,
I.CUXBOXQTY,
I.beforeconversionuom,
I.Cuxtrayname,
I.CUXLGORT,
I.afterconversionuom,
I.QTY,
I.ponumber,
I.CUXCUZZHH,
'0',
SYSDATE(),
'SYSTEM'
);
COMMIT;
END IF;
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
BEGIN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQLCODE));
VERRINFO:=SUBSTR(SQLERRM,1,100);
INSERT INTO ERRORINFO(CUXTABLE,CUXPROCEDURE,ERRORMESSAGE,ERRORTIME) VALUES('CUX_FinishedProduct','CUX_FinishedProcedure',VERRINFO,SYSDATE());
COMMIT;
END;
END CUX_FinishedProcedure;