Home โ€บ Interview Questions โ€บ Write a stored procedure that loops from 1 to 10.

Write a stored procedure that loops from 1 to 10.

๐ŸŸข Easy Coding Fresher level
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