如何从表中获取特定值并将其存储在存储过程中的变量中

时间:2013-06-28 07:00:05

标签: mysql

我试图将数据库中的值存储到变量内部过程中并将其值增加1.这就是我所做的:

CREATE DEFINER=`satish`@`%` PROCEDURE `p_authTeacher`(
IN username VARCHAR(35),
IN pwd VARCHAR(35),
OUT msg INT,  
OUT msg1 INT,
OUT msg2 INT
)
BEGIN
select (COUNT(*) > 0) INTO @result from login where User_Name = username and    User_Password = md5(pwd);

SET msg = @result;  
IF @result = 1 THEN
select (COUNT(*)>0) into @result1 from login where User_Name = username and User_Password = md5(pwd) and Is_New ='F';
if @result1= 1 Then
UPDATE login SET Last_login=now() where User_Name = username and User_Password = md5(pwd);
SET msg1 = @result1;
END IF;
if @result1= 0 Then
UPDATE login SET Last_login=now() where User_Name = username and User_Password = md5(pwd);
SET msg1 = @result1;    
END IF;
END IF; 
IF @result = 0 THEN
    select Password_Attempts into @attempts from login where User_Name = username ;
    SET msg2 = @attempts;
update login set Password_Attempts=1 where username = uname;
END IF;
END

尝试存储列(Password_Attempts)的值,​​其中username = uname of login table。 将1添加到其中并更新到数据库中。但当然我得到了Syntax错误。请帮帮我。即使用户名和密码不匹配,最后一个if块也不起作用。

1 个答案:

答案 0 :(得分:1)

有关SELECT ... INTO的正确语法,请参阅this链接。您应该将INTO放在FROM之前:

select Password_Attempts into @attempts from login where User_Name = uname ;