0

I would like to execute a loop in phpmyadmin which inserts rows in a table. So far I have:

DELIMITER $$

DROP PROCEDURE IF EXISTS insert_my_rows()

CREATE PROCEDURE insert_my_rows()
BEGIN
DECLARE i INT DEFAULT 376;

WHILE i<405 DO
        INSERT INTO wp_term_relationships(object_id,term_taxonomy_id,term_order) VALUES (i,16,0);
        SET i=i+1;
END WHILE;
END $$

DELIMITER ;

CALL insert_my_rows()

With this, I get an 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 'DELIMITER$$

DROP PROCEDURE IF EXISTS insert_my_rows()

CREATE PROCEDURE ins' at line 1 
6
  • Remove the quotes from around the column name Commented Nov 22, 2014 at 6:27
  • i still get #1305 - PROCEDURE sunny.insert_my_rows does not exist Commented Nov 22, 2014 at 6:40
  • Can you please show your procedure? Commented Nov 22, 2014 at 11:26
  • 1
    the clue is in the first line Commented Nov 22, 2014 at 14:25
  • 1
    @bsapaka I knew the error is not with the code you posted earlier and that is why I asked you for the entire code. Kums posted the correct answer below Change DROP PROCEDURE IF EXISTS insert_my_rows(); to DROP PROCEDURE IF EXISTS insert_my_rows; Commented Nov 22, 2014 at 19:17

3 Answers 3

1

Syntax for the DROP PROCEDURE statement is incorrect!

Change

DROP PROCEDURE IF EXISTS insert_my_rows()

to

DROP PROCEDURE IF EXISTS insert_my_rows;
Sign up to request clarification or add additional context in comments.

Comments

0

You need to end the statement with the proper delimiter. Change END to END$$.

Comments

0

You must change the delimiter only while you make blocks of statements, so during the procedure definition. The DROP PROCEDURE and CALL statements needs delimiters too.

DROP PROCEDURE IF EXISTS insert_my_rows;

DELIMITER $$

CREATE PROCEDURE insert_my_rows()
BEGIN
    DECLARE i INT DEFAULT 376;

    WHILE i<405 DO
        INSERT INTO wp_term_relationships(object_id,term_taxonomy_id,term_order) VALUES (i,16,0);
        SET i=i+1;
    END WHILE;
END $$

DELIMITER ;

CALL insert_my_rows();

DROP PROCEDURE IF EXISTS insert_my_rows;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.