我在显示错误消息方面遇到了一些问题,这就是我写的内容:
DELIMITER go
Create procedure getusers(
IN iEmailAddress varchar(30),
IN iPassword varchar(30))
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
-- this one is for checking the empty email address and it suppose to
-- display an error message.
Select EmailAddress from users
where not exists( select EmailAddress
from users where EmailAddress=iEmailAddress
SIGNAL SQLSTATE VALUE '99999'
SET MESSAGE_TEXT = 'Email Address does not exists';
)
End
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
-- this one is for checking the empty password and it suppose to
-- display an error message.
Select Password from users
where not exists( select Password
from users where Password=iPassword
SIGNAL SQLSTATE VALUE '99999'
SET MESSAGE_TEXT = 'Password does not exists';
)
End
BEGIN
Select EmailAddress, Password,Salt,RoleID,UserID from users
where EmailAddress = iEmailAddress and PASSWORD = iPassword;
End
go
DELIMITER ;
我收到一条错误消息:
MySQL说:文档 1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在'SIGNAL SQLSTATE VALUE'999999'附近使用正确的语法 SET MESSAGE_TEXT ='电子邮件地址不在第10行“
我已将该链接用于参考:http://dev.mysql.com/doc/refman/5.7/en/signal.html
答案 0 :(得分:0)
我解决了问题,解决方案是:
> DELIMITER go Create procedure getusers( IN iEmailAddress varchar(30),
> IN iPassword varchar(30)) BEGIN declare checkemailcount int; declare
> checkpasswordcount int;
>
> select count(emailaddress) into checkemailcount from users where
> emailaddress = iEmailaddress;
>
> select count(Password) into checkpasswordcount from users where
> Password = iPassword;
>
> --check if emailaddress not exists
>
> If(checkemailcount!=1) then SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT =
> 'Email address is not found';
>
> --check if password not exists
>
> Elseif (checkpasswordcount!=1) then SIGNAL SQLSTATE '45000' SET
> MESSAGE_TEXT = 'Invalid Password'; else
>
> select emailaddress,password,salt,UserID from users where
> emailaddress=iEmailaddress and password = iPassword;
>
>
> End if; End go DELIMITER ;