CREATE OR REPLACE PROCEDURE ATUALIZA_RETIRADA_EXP(
    P_FILIAL IN NOTAFISCAL.CDFILIAL%TYPE,
    P_LANCTONF IN NOTAFISCAL.NRLANCTONF%TYPE)

IS

BEGIN
   /*LISTA AS RETIRADAS */
   FOR C_LANCTOEST IN (SELECT R.CDFILIAL, R.NRLANCESTQ, R.CDFILIALRET, R.NRLANCESTRET
                         FROM NOTAFISCAL N, LANCTOESTOQ LA, NFRELACRETIR R
                        WHERE N.CDFILIAL = P_FILIAL
                          AND N.NRLANCTONF = P_LANCTONF
                          AND N.CDFILIAL  = LA.CDFILIAL
                          AND N.NRLANCTONF = LA.NRLANCTONF
                          AND LA.CDFILIAL   = R.CDFILIAL
                          AND LA.NRLANCESTQ = R.NRLANCESTQ

   ) LOOP
      DELETE FROM LANCTOESTOQ
      WHERE CDFILIAL   = C_LANCTOEST.CDFILIALRET
        AND NRLANCESTQ = C_LANCTOEST.NRLANCESTRET;
   END LOOP;
END;
/