SET TERM ^ ;

CREATE OR ALTER procedure SP_COPIAR_PERMISSAO_WHATSAPP (
    DE integer,
    PARA integer,
    LIMPAR integer)
as
declare variable ID integer;
declare variable WHATSAPP_COMANDOS_ID integer;
begin

  if(LIMPAR = 1)then
  begin
    delete from tbwhatsapp_tarefa_perm f where f.WHATSAPP_ID = :PARA;
  end

  for
    select
        T.ID,
        T.WHATSAPP_COMANDOS_ID
    from tbwhatsapp_tarefa_perm  T
    where T.WHATSAPP_ID = :DE
  into
    :ID,
    :WHATSAPP_COMANDOS_ID
  do begin

     update or insert into tbwhatsapp_tarefa_perm (WHATSAPP_ID, WHATSAPP_COMANDOS_ID)
        values (:PARA, :WHATSAPP_COMANDOS_ID)
     matching (WHATSAPP_ID, WHATSAPP_COMANDOS_ID);

  end

end
^

SET TERM ; ^

