• + 0 comments

    DELIMITER // CREATE PROCEDURE p1(IN n INT) BEGIN DECLARE i INT DEFAULT 3; DECLARE result VARCHAR(10000) DEFAULT '2'; DECLARE flag INT DEFAULT 0; DECLARE j INT; loop1:LOOP SET flag = 0; SET j = i; loop2:LOOP SET j = j-1; IF j = 1 THEN LEAVE loop2; END IF; IF i%j = 0 THEN SET flag = 1; LEAVE loop2; END IF; END LOOP loop2; IF flag = 0 THEN SET result = CONCAT(result,'&',i); END IF; IF i = n THEN LEAVE loop1; END IF; SET i = i+1; END LOOP loop1; SELECT result; END // DELIMITER ;

    CALL p1(1000);