DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`niching`(IN i_ini INT, IN i_end INT , IN i_bal INT, IN i_col INT ) BEGIN DECLARE i INT(5); DECLARE j INT(5); DROP TEMPORARY TABLE IF EXISTS labels; CREATE TEMPORARY TABLE `labels` (`label` VARCHAR(15) NULL) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; WHILE i_ini <= i_end DO SET i = i_bal; WHILE i > 0 DO SET j = i_col; IF j = 0 THEN INSERT INTO labels(label) VALUES (CONCAT(i_ini,IF(i=0,' ',char(64 + i)))); ELSE WHILE j > 0 DO INSERT INTO labels(label) VALUES (CONCAT(i_ini,char(64 + i), j)); SET j = j - 1; END WHILE; END IF; SET i = i - 1; END WHILE; SET i_ini = i_ini + 1; END WHILE; SELECT CONCAT('*',label,'*') as label, label as id FROM labels; END$$ DELIMITER ;