mysql过程中的参数错误

时间:2012-06-22 18:32:48

标签: mysql parameters mysql-error-1064 ddl procedure

此代码显示参数声明中的语法错误。请帮我解决

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `ADDCOURSE`(@Course varchar(45),@Branch varchar(45),@Batch INT)
BEGIN
    DECLARE I INT;
    SET I=1;
    LABEL1: LOOP
        INSERT INTO course 
        (Course, Branch, Batch)
         VALUES(@Course, @Branch, I);
        IF I <= @Batch THEN
            SET I=I+1;
            ITERATE LABEL1;
        END IF;
        LEAVE LABEL1;
     END LOOP LABEL1;
END

1 个答案:

答案 0 :(得分:1)

请改为尝试:

DELIMITER $$

CREATE DEFINER = `root`@`localhost` PROCEDURE ADDCOURSE(
    Course varchar(45), Branch varchar(45), Batch INT
)

BEGIN
    DECLARE I INT;
    SET I = 1;
    LABEL1: LOOP
        INSERT INTO course 
        (Course, Branch, Batch)
         VALUES(@Course, @Branch, I);
        IF I <= @Batch THEN
            SET I=I+1;
            ITERATE LABEL1;
        END IF;
        LEAVE LABEL1;
    END LOOP LABEL1;
END

$$

CREATE DEFINER = `root`@`localhost` PROCEDURE ADDCOURSE( Course varchar(45), Branch varchar(45), Batch INT ) BEGIN DECLARE I INT; SET I = 1; LABEL1: LOOP INSERT INTO course (Course, Branch, Batch) VALUES(@Course, @Branch, I); IF I <= @Batch THEN SET I=I+1; ITERATE LABEL1; END IF; LEAVE LABEL1; END LOOP LABEL1; END $$