DELIMITER $$

CREATE OR REPLACE PROCEDURE select_nextval(IN max_alter int, IN slp float, IN run_time int)
BEGIN
    DECLARE seq INT DEFAULT 0;
    DECLARE start DATETIME;
    DECLARE current DATETIME;

    SET start = NOW();
    SET current = NOW();

    WHILE TIMESTAMPDIFF(MINUTE, start, current) < run_time DO
        SET seq = NEXTVAL(s);
        commit;
        SELECT seq;

        IF seq > max_alter THEN
            ALTER SEQUENCE s START 2 RESTART 2 INCREMENT BY 0;
        END IF;

        SET current = NOW();

        SELECT SLEEP(slp);

    END WHILE;
END $$

DELIMITER ;
