CREATE OR REPLACE
PROCEDURE RECAL_LANCCUS(
   P_CDEMPRESA IN EMPRESA.CDEMPRESA%TYPE,
   P_DTINICIO  DATE,
   P_DTFINAL   DATE)
IS
   V_CDCONTCTBL VARCHAR2(20);
BEGIN
   FOR C_LANCCCUSTO IN
   (SELECT LC.NRLANCCONT, LC.NRSEQLANC
      FROM LANCCCUSTO LC
     WHERE LC.CDEMPRESA  = P_CDEMPRESA
       AND LC.DTCOMPCUSTO BETWEEN P_DTINICIO AND P_DTFINAL) LOOP

       SELECT CDCONTCTBL
         INTO V_CDCONTCTBL
         FROM LANCCONT L
        WHERE L.NRLANCCONT = C_LANCCCUSTO.NRLANCCONT
          AND L.NRSEQLANC  = C_LANCCCUSTO.NRSEQLANC
          AND L.CDEMPRESA  = P_CDEMPRESA;

      UPDATE LANCCCUSTO
         SET CDCONTCTBL = V_CDCONTCTBL
       WHERE NRLANCCONT = C_LANCCCUSTO.NRLANCCONT
         AND NRSEQLANC  = C_LANCCCUSTO.NRSEQLANC
         AND CDEMPRESA  = P_CDEMPRESA;
   END LOOP;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('RECAL_LANCCUS','5.30.000'); END;
/

