CREATE OR REPLACE PROCEDURE CANCELA_SOLEMERGPROD_CKLISTS
(
P_CDFILIAL IN VARCHAR2,
P_NRSOLEMERGPROD 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 CKLISTSOLEMERGPROD
       WHERE CDFILIAL = P_CDFILIAL
         AND NRSOLEMERGPROD = P_NRSOLEMERGPROD       
   ) LOOP
      BEGIN
         /*Exclui da tabela de relacao de checklists*/
         DELETE FROM CKLISTSOLEMERGPROD
          WHERE CDFILIAL = P_CDFILIAL
            AND NRSOLEMERGPROD = P_NRSOLEMERGPROD
            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;
/