CREATE OR REPLACE PROCEDURE REVERTE_LOTE (
   P_CDEMPRESA IN EMPRESA.CDEMPRESA%TYPE,
   P_CDLOTE    IN LANCLOTE.CDLOTE%TYPE  )
AS
V_VERSAO     VARCHAR2(1);
BEGIN
  FOR C_LANCLOTE IN (SELECT DISTINCT LANCLOTE.NRLANCDEFI, LANCLOTE.CDEMPRESA
                       FROM LANCLOTE
                      WHERE (LANCLOTE.CDEMPRESA = P_CDEMPRESA)
                        AND (LANCLOTE.CDLOTE    = P_CDLOTE)  )LOOP

   DELETE
     FROM LANCCONT
    WHERE LANCCONT.CDEMPRESA   = C_LANCLOTE.CDEMPRESA
      AND LANCCONT.NRLANCCONT  = C_LANCLOTE.NRLANCDEFI;
  END LOOP;
UPDATE CAPALOTE
   SET CAPALOTE.IDLOTE = 'D'
   WHERE (CAPALOTE.CDEMPRESA = P_CDEMPRESA)  AND
         (CAPALOTE.CDLOTE    = P_CDLOTE);

END;
/