如何在MySQL中使用循环/重复功能?

时间:2013-09-03 16:22:58

标签: mysql sql loops

我试图摆脱一个无聊的任务,即点击我的GUI的创建按钮来创建新行,所以我决定定义一个函数来执行它,因为我想要它多次至... 这是代码,但它在NAVICAT中返回错误:

CREATE FUNCTION AddRow (number INT)
    BEGIN
        SET @x = 0;
    REPEAT
        INSERT INTO 'result' () VALUES ()
        SET @x += 1;
    UNTIL x > @number END REPEAT;

    END
call AddRow (10)

错误:

[SQL]CREATE FUNCTION AddRow (number INT)
    BEGIN
        SET @x = 0;
    REPEAT
        INSERT INTO 'result' () VALUES ()
        SET @x += 1;
    UNTIL x > @number END REPEAT;

    END
call AddRow (10)

[Err] 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 'BEGIN
        SET @x = 0;
    REPEAT
        INSERT INTO 'result' () VALUES ()
        SET @x += ' at line 2

0 个答案:

没有答案