A stored procedure is a group of SQL statements that form a logical unit and perform a particular task. Is a parameter in the procedure. One or more parameters can be declared in a CREATE PROCEDURE statement.Stored procedures are used to encapsulate a set of operations or queries to execute on a database server.
Code:
CREATE PROCEDURE RepeatLoopProc()
BEGIN
DECLARE x INT;
DECLARE str VARCHAR(255);
SET x = 1;
SET str = '';
REPEAT
SET str = CONCAT(str,x,',');
SET x = x + 1;
UNTIL x > 5
END REPEAT;
SELECT str;
END$$
DELIMITER ;
Bookmarks