使用MySQL Workbench 6.0存储过程获取语法错误

时间:2014-06-13 10:25:55

标签: mysql stored-procedures mysql-workbench

我是mysql的新手,我和我编写了一个存储过程,我总是遇到语法错误,我正在使用SQL Workbench 6.0,有人可以帮助我知道我做错了什么。

    CREATE DEFINER=`root`@`localhost` PROCEDURE `loginAuthentication`(IN user_name VARCHAR(45),IN pass VARCHAR(45),OUT returnvalue INT)

    BEGIN
           DECLARE no_of_records INT; (Syntax Error on this Line)

           SELECT COUNT(*) INTO no_of_records
           FROM tablename.registration 
           WHERE tablename.registration.user_name=user_name AND tablename.registration.pass=pass; 

           IF no_of_records = 1 THEN (Syntax Error on this Line)
           SET returnvalue = 1;
           END IF; (Syntax Error on this Line)
    END; (Syntax Error on this Line)

1 个答案:

答案 0 :(得分:2)

您必须更改分隔符。否则,MySQL认为您的程序在第一个;

之后结束

像这样写:

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `loginAuthentication`(IN user_name VARCHAR(45),IN pass VARCHAR(45),OUT returnvalue INT)

BEGIN
       DECLARE no_of_records INT;

       SELECT COUNT(*) INTO no_of_records
       FROM tablename.registration 
       WHERE tablename.registration.user_name=user_name AND tablename.registration.pass=pass; 

       IF no_of_records = 1 THEN 
       SET returnvalue = 1;
       END IF;
END $$
DELIMITER ;

顺便说一句,Workbench与它无关。它只是MySQL的客户端。