Write a stored procedure that loops from 1 to 10.
1Times asked
Aug 2026Last seen
Aug 2026First seen
๐ก Model Answer
A stored procedure that loops from 1 to 10 can be written in MySQL as follows:
sql
DELIMITER $$
CREATE PROCEDURE LoopOneToTen()
BEGIN
DECLARE i INT DEFAULT 1;
WHILE i <= 10 DO
SELECT i;
SET i = i + 1;
END WHILE;
END$$
DELIMITER ;Executing CALL LoopOneToTen(); will return a result set with the numbers 1 through 10. The procedure uses a DECLARE statement to initialize a counter, a WHILE loop to iterate, and a SELECT to output each value. This example illustrates basic loop control in MySQL stored procedures.
This answer was generated by AI for study purposes. Use it as a starting point โ personalize it with your own experience.
๐ค Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI โ Starts at โน500