简体   繁体   中英

MySQL Stored Procedure error

I have a simple stored procedure which inserts records into four character fields in table. Below is the procedure

CREATE PROCEDURE dowhile()

BEGIN

DECLARE I INT DEFAULT 5

v1loop: WHILE I < 10000 DO

   INSERT INTO TestTable1(A,B,C,D)

   SELECT CONCAT(I,'A'), CONCAT(I,'B'), CONCAT(I,'C'), CONCAT(I,'D')

   SET I = I + 1

END WHILE v1loop

END;

Checked online - there are no free MSSQL to MYSQL SQL Conversion Tools

Error is - SQL Syntax Error in Insert - SELECT Statement

I have checked the syntax this seem to be correct.

Any pointers for this would be helpful.

Not to bad actually, you just need to add some semi-colons and change MySQL's default delimiter. This needs to be done since we're using SQL inside SQL.

DELIMITER $$

CREATE PROCEDURE dowhile()

BEGIN

DECLARE I INT DEFAULT 5;

v1loop: WHILE I < 10000 DO

   INSERT INTO TestTable1(A,B,C,D)

   SELECT CONCAT(I,'A'), CONCAT(I,'B'), CONCAT(I,'C'), CONCAT(I,'D');

   SET I = I + 1;

END WHILE v1loop;

END$$

DELIMITER ;

Just tested this on my MySQL server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM