Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Created August 28, 2013 20:17
Show Gist options
  • Select an option

  • Save raphaelchaib/6370688 to your computer and use it in GitHub Desktop.

Select an option

Save raphaelchaib/6370688 to your computer and use it in GitHub Desktop.
MySQL: WHILE statement schema (Need to finish it)
DELIMITER $$
CREATE PROCEDURE fillPaisesNome()
BEGIN
DECLARE paisesNoName INT;
DECLARE controle INT;
SET paisesNoName = (SELECT COUNT(*) FROM `io_paises` WHERE `io_paises`.`nome` IS NULL);
SET controle = 0;
WHILE controle < paisesNoName DO
UPDATE `io_paises` AS `pais`
SET `pais`.`nome` = (
SELECT `trans`.`nome`
FROM `io_paises_translation` AS `trans`
WHERE `trans`.`id` = `pais`.`id`
)
WHERE `pais`.`nome` IS NULL;
commit;
SET controle = controle + 1;
END WHILE;
END;
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment