ALTER TABLE FILIAL ADD IDEMISFILNFSERV VARCHAR2(01) DEFAULT 'P'
/

BEGIN
   FOR C_FILIAL IN (SELECT IDENDEMISFIL, CDFILIAL
                      FROM FILIAL
                     ORDER BY CDFILIAL) LOOP
                     
      IF C_FILIAL.IDENDEMISFIL = 'I' THEN
         UPDATE FILIAL 
            SET IDEMISFILNFSERV = 'P'
          WHERE CDFILIAL = C_FILIAL.CDFILIAL;                     
      ELSE
         UPDATE FILIAL 
            SET IDEMISFILNFSERV = C_FILIAL.IDENDEMISFIL
          WHERE CDFILIAL = C_FILIAL.CDFILIAL;      
      END IF;
   END LOOP;
   COMMIT;
END;
/ 