Write a stored procedure that loops from 1 to 10.
1
Times asked
Aug 2026
Last seen
Aug 2026
First 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.
Sign in to unlock the rest of this answer
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