BEGIN
   FOR C_LANC IN (SELECT CDEMPRESA, NRLANCCONT, CDCONTCTBL, COUNT(*) FROM LANCCCUSTO
                   WHERE VRLANCCUST IS NULL
                   GROUP BY  CDEMPRESA, NRLANCCONT, CDCONTCTBL
                  HAVING COUNT(*) = 1) LOOP
      UPDATE LANCCCUSTO LC
         SET VRLANCCUST = (SELECT VRLANCAMENT FROM LANCCONT LA WHERE LC.CDEMPRESA = LA.CDEMPRESA AND LC.NRLANCCONT = LA.NRLANCCONT AND LC.CDCONTCTBL = LA.CDCONTCTBL) 
       WHERE LC.VRLANCCUST IS NULL
         AND LC.CDEMPRESA  = C_LANC.CDEMPRESA
         AND LC.NRLANCCONT = C_LANC.NRLANCCONT
         AND LC.CDCONTCTBL = C_LANC.CDCONTCTBL;
     COMMIT;
   END LOOP;
END;
/