1

When running my query I am getting this:

error:

#1064 - 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

SQL:

DROP PROCEDURE IF EXISTS insertPromos;
CREATE PROCEDURE insertPromos()
BEGIN
  DECLARE int_val INT DEFAULT 0;
  insertPromosLoop : LOOP

  IF (int_val = 501) THEN
    LEAVE insertPromosLoop;
  END IF;
    INSERT INTO `promo_code` (`code`, `valid_from` ,`valid_to` , `free_period`)VALUES (CONCAT('PROMO', int_val),  '2013-10-10',  '2013-11-10',  'P1M');
    SET int_val = int_val +1;
  END LOOP; 
END;
CALL insertPromos();

1 Answer 1

2

You need to define a new delimiter

delimiter |

DROP PROCEDURE IF EXISTS insertPromos |

CREATE PROCEDURE insertPromos()
BEGIN
  DECLARE int_val INT DEFAULT 0;
  insertPromosLoop : LOOP

  IF (int_val = 501) THEN
    LEAVE insertPromosLoop;
  END IF;
    INSERT INTO `promo_code` (`code`, `valid_from` ,`valid_to` , `free_period`)VALUES (CONCAT('PROMO', int_val),  '2013-10-10',  '2013-11-10',  'P1M');
    SET int_val = int_val +1;
  END LOOP; 
END
|

delimiter ;

CALL insertPromos();

Otherwise the procedure definition would end at the first ; which would not be correct.

Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant, that worked. Thanks a lot. First time using procedures.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.