CREATE OR REPLACE PROCEDURE CANCELA_PLANAPREINF_CKLISTS
(
P_CDFILIAL IN VARCHAR2,
P_NRPLANAPREINF IN NUMBER,
P_CDOPERADOR IN VARCHAR2,
P_NRORG IN NUMBER,
P_NRLISTAERROS OUT NUMBER
) 
AS
V_NRORDEM NUMBER;
BEGIN
   V_NRORDEM := 1;

   FOR CUR_CKLISTS IN
   (
      SELECT NRCKLISTPRODINF
        FROM CKLISTPLANAPREINF
       WHERE CDFILIAL = P_CDFILIAL
         AND NRPLANAPREINF = P_NRPLANAPREINF       
   ) LOOP
      BEGIN
         /*Exclui a relacao de checklists do planejamento de producao*/
         DELETE FROM CKLISTPLANAPREINF
          WHERE CDFILIAL = P_CDFILIAL
            AND NRPLANAPREINF = P_NRPLANAPREINF
            AND NRCKLISTPRODINF = CUR_CKLISTS.NRCKLISTPRODINF;
         /*Exclui o checklist se estiver pendente*/
         EXCLUI_CKLISTPRODINF(P_CDFILIAL, CUR_CKLISTS.NRCKLISTPRODINF);
      EXCEPTION
         WHEN OTHERS THEN
            INSERE_LISTA_ERROS(P_CDFILIAL, SQLERRM, P_CDOPERADOR, P_NRORG, P_NRLISTAERROS, V_NRORDEM);
            V_NRORDEM := V_NRORDEM + 1;
      END;
   END LOOP;
END;
/