BEGIN

FOR C_DELCUSLP IN
 (SELECT
    CDFILIAL,
    CDPRODUTO,
    DTPOSESTCON
  FROM
    POSESTCONS  
  WHERE
   (NVL(QTESTDIACON , 0) +
    NVL(QTESTANTCON , 0) +
    NVL(VRESTANTCON , 0) +
    NVL(VRESTANTCOM1, 0) +
    NVL(VRESTANTCOM2, 0) +
    NVL(VRESTBRUTCON, 0) +
    NVL(VRESTBRUTCM1, 0) +
    NVL(VRESTBRUTCM2, 0) +
    NVL(VRBRUTANTCON, 0) +
    NVL(VRBRUTANTCM1, 0) +
    NVL(VRBRUTANTCM2, 0) = 0) AND

   (
    (NVL(VRCUSPRLISTP, 0) +
     NVL(VRCUSPRLISM1, 0) +
     NVL(VRCUSPRLISM2, 0) > 0) OR

    (NVL(VRPRCUSTOAF , 0) +
     NVL(VRPRCUSAFM1 , 0) +
     NVL(VRPRCUSAFM2 , 0) > 0)
   )   )
LOOP 
  DELETE FROM POSESTCONS
  WHERE
    CDFILIAL    = C_DELCUSLP.CDFILIAL    AND
    CDPRODUTO   = C_DELCUSLP.CDPRODUTO   AND
    DTPOSESTCON = C_DELCUSLP.DTPOSESTCON;

  COMMIT;
END LOOP;

END;
/