DECLARE

lDecBaselineFixedValue tabMetricHist_24.collectedValue_fixed%TYPE;

BEGIN

lDecValorBaseColetado := 0;

FOR f IN (

SELECT cellServer

, metric

, objectName

, objectType

, MIN(collectionMoment) as MinCollect

FROM tabMetricHist_1hr

WHERE tipometrica = 'Cumulative'

GROUP BY cellServer

, metric

, objectName

, objectType

) LOOP

SELECT mh.valorcoleta_num INTO lDecBaselineFixedValue

FROM tabMetricHist_1hr mh

WHERE mh.cellServer = f.cellServer

AND mh.metric = f.metric

AND mh.objectName = f.objectName

and mh.objectType = f.objectType

AND mh.collectionMoment = f.MinCollect;

IF (lDecBaselineFixedValue > 0) THEN

UPDATE tabMetricHist_1hr mhu

SET mhu.collectedValue_fixed = mhu.valorcoleta_num - lDecBaselineFixedValue

WHERE mhu.cellServer = f.cellServer

AND mhu.metric = f.metric

AND mhu.objectName = f.objectName

AND mhu.objectType = f.objectType;

END IF;

END LOOP;

COMMIT;

END;