Parijat Kalia
Parijat Kalia

Reputation: 5085

MySQL stored procedure syntax pain

I am trying to create a simple Stored procedure that allows me to conduct mass inserts, However I am running into syntactical troubles and unable to figure out where what's going wrong, despite comparing my procedure syntax to existing examples, and it seems to be correct.

CREATE PROCEDURE populateUserTable()
 BEGIN
  DECLARE counter int(10);
  SET counter = 1;
 WHILE counter < 101 DO
  INSERT INTO user(userid) values(counter);
  SET counter = counter + 1
 END WHILE;
END

Upon running, MYSQL states: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

and highlits this guy:

CREATE PROCEDURE populateUserTable( ) BEGIN DECLARE counter INT( 10 ) ;

What's up here?

Upvotes: 0

Views: 388

Answers (1)

Ed Heal
Ed Heal

Reputation: 60007

Have you used

DELIMITER $$

At the start?

Try

DELIMITER $$
CREATE PROCEDURE populateUserTable()
 BEGIN
   DECLARE counter int(10);
   SET counter = 1;
   WHILE counter < 101 DO
      INSERT INTO user(userid) values(counter);
      SET counter = counter + 1
   END WHILE;
END $$
DELIMITER ;

Upvotes: 1

Related Questions