MySql例程问题

时间:2012-10-25 21:57:22

标签: mysql routines

我遇到制作MySql例程的问题。

以下是代码:

DELIMITER '$$';
CREATE PROCEDURE User.Login(IN UserName CHAR(32), IN PWord CHAR(32))
BEGIN
Select `userID`, `userType`, `userMainEmail`, `groupID`
    From `at_users`
    Where `userName` = UserName And `userPass` = PWord
    LIMIT 1
FOR UPDATE;

    Update `at_users`
    Set `lastLoginAt` = now()
    Where `userName` = UserName And `userPass` = PWord;
END$$

它应该做的是一个简单的登录任务,几乎在任何地方完成...获取用户记录,然后用now()更新表()

我在创建它时得到的是:

#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 '' at line 12

第12行是END $$之前的行

是的,所有字段和表都存在。 :)

编辑:新代码

DELIMITER //;
CREATE PROCEDURE User.Login(IN UserName CHAR(32), IN PWord CHAR(32))
BEGIN
Select `userID`, `userType`, `userMainEmail`, `groupID`
    From `at_users`
    Where `userName` = UserName And `userPass` = PWord
    LIMIT 1
FOR UPDATE;

    Update `at_users`
    Set `lastLoginAt` = now()
    Where `userName` = UserName And `userPass` = PWord;
END//
DELIMITER ;

我在登录并选择适当的数据库到USE后,从命令行尝试这个确切的代码。

在最后一行'DELIMITER;'之后没有任何反应,我留在 - >线

1 个答案:

答案 0 :(得分:0)

知道了。

以下是我最终必须使用的代码:

DELIMITER //
CREATE PROCEDURE UserLogin(IN UserName CHAR(32), IN PWord CHAR(32))
    BEGIN
        Select `userID`, `userType`, `userMainEmail`, `groupID`
        From `at_users`
        Where `userName` = UserName And `userPass` = PWord
        LIMIT 1
        FOR UPDATE;

        Update `at_users`
        Set `lastLoginAt` = now()
        Where `userName` = UserName And `userPass` = PWord;
    END//
DELIMITER ;