2

Total noob in Mysql alert.

need to run simple For loop to insert data into table. Copying For loop example from docs:

CREATE PROCEDURE doiterate(p1 INT)
BEGIN
  label1: LOOP
    SET p1 = p1 + 1;
    IF p1 < 10 THEN
      ITERATE label1;
    END IF;
    LEAVE label1;
  END LOOP label1;
  SET @x = p1;
END;

Shows bunch of errors in Workbench editor window:

enter image description here

Eg, first error for "p1" tells:

"p1" is not valid for this position, expecting an identifier

Checked MySQL version - SELECT @@version;, its 5.7, the same as from docs page. Workbench version is 8.0

Not sure what other info I can provide.

3
  • What happens if you try to create and then run the stored proc? Commented Nov 11, 2019 at 10:29
  • 1
    Have you set delimiters (procedure syntaxes for me if I do) and runs fine.. Commented Nov 11, 2019 at 10:44
  • Thanks, wasnt able to answer quicker. Answer solved the problem Commented Nov 11, 2019 at 15:07

1 Answer 1

1

On MySQL Workbench

when creating a stored routine on Query Tab you need to explicitly set delimiter before create procedure..

enter image description here

DELIMITER $$ -- this symbol can be anything other than default ;
CREATE PROCEDURE doiterate(p1 INT)
BEGIN
  label1: LOOP
    SET p1 = p1 + 1;
    IF p1 < 10 THEN
      ITERATE label1;
    END IF;
    LEAVE label1;
  END LOOP label1;
  SET @x = p1;
END $$
DELIMITER ; -- once completed we are resting back to default

When creating a routine under Routine Tab you need not to include delimiter

enter image description here

Since when clicking Apply it will automatically builds it.

enter image description here

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

Comments

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.