触发器写法:
function CF_SHOULD_BACK_TIMEFormula return Number is
--其他:取MES工时按工段分别统计产量、投入工时合计:应回报工时=移动数量*[∑(各工段投入工时合计/各工段实际产量)]
V_SHOULD_BACK_TIME NUMBER(10, 2) := 0; --应回报工时
V_MAX_QUANTITY NUMBER(10, 2) := 0; --移动数量
V_DAILY_TIME NUMBER(10,2):=0;
V_MES_DAILY_HOUR NUMBER(10,2):=0;
begin
V_MAX_QUANTITY := nvl(CF_MAX_QUANTITYFormula, 0); --移动数量
begin
select nvl(sum(hours / work_quantity),0) * V_MAX_QUANTITY
into V_SHOULD_BACK_TIME
from (select sum(mfw.hours) hours,
sum(nvl(work_quantity, 0)) work_quantity,
code
FROM mes_fm_work_production_daily mfw ,CUX_PROD_LINE_SITE CPLS
where mfw.task_order_code = :WIP_ENTITY_NAME
and mfw.work_line = cpls.line_code
and mfw.code = cpls.site_code
and CPLS.DEPARTMENT_CODE=substr(:RESOURCE_CODE,1,3)
AND mfw.WORK_DATE<= NVL(to_date(:P_END_DATE,'YYYY-MM-DD'), TRUNC(SYSDATE))
group by code)
where nvl(work_quantity,0) <> 0;
exception when others then
V_SHOULD_BACK_TIME :=0;
end ;
return V_SHOULD_BACK_TIME;
end;
来源:https://www.cnblogs.com/lanminghuai/p/11354317.html