Skip to content

Instantly share code, notes, and snippets.

@petronioamaral
Last active August 5, 2020 04:34
Show Gist options
  • Save petronioamaral/9653eed6a5b9dc3e6fcec2e6833e7f66 to your computer and use it in GitHub Desktop.
Save petronioamaral/9653eed6a5b9dc3e6fcec2e6833e7f66 to your computer and use it in GitHub Desktop.
DROP PROCEDURE IF EXISTS dorepeat

CREATE PROCEDURE dorepeat()
BEGIN
DECLARE someId INT;
DECLARE city CHAR(50);
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR select id_cidade,cidade from cepbr_cidade ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;     

OPEN cur1;

read_loop: LOOP

FETCH cur1 INTO someId, city;

update cepbr_cidade set nome_sem_acento = fn_remove_accents(city) where id_cidade = someId;

IF done THEN

CLOSE cur1;
  LEAVE read_loop;
END IF;

END LOOP read_loop;
END;

CALL dorepeat();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment