我尝试创建一个函数,即如果用户名存在,则会将随机数和字符作为单个字符串返回,但我尝试了下面的代码,抛出如下的语法错误,你能帮助找到问题,我知道有声明字符串和返回字符串的问题,但无法找到问题。感谢提前回复
DELIMITER //
create function verifyEmail(userName varchar(25))
RETURNS TEXT
BEGIN
if EXISTS(select * from userdetails where name = userName)
then
SELECT @randomPass := select concat( char(round(rand()*36)+1), char(round(rand()*36)+1), char(round(rand()*36)+1));
return @randomPass;
else
return "not_exist";
end if;
end //
DELIMITER //
#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在'select concat(char(round(rand()* 36)+1)附近使用正确的语法,char(round(rand()* 36)+1),char (圆形(ra'在第6行
答案 0 :(得分:0)
您错过了此行的结束)
:
SELECT @randomPass := select concat( char(round(rand()*36)+1), char(round(rand()*36)+1), char(round(rand()*36)+1);
应该是
SELECT @randomPass := select concat( char(round(rand()*36)+1), char(round(rand()*36)+1), char(round(rand()*36)+1));
答案 1 :(得分:0)
DELIMITER //
create function verifyEmail(userName varchar(25))
RETURNS TEXT
BEGIN
DECLARE randomPass VARCHAR(8);
if EXISTS(select id from userdetails where name = userName)
THEN
SET randomPass = concat( char(rand()*25+65),char(rand()*25+65),char(rand()*25+65),char(rand()*25+65),char(rand()*25+65),char(rand()*25+65),char(rand()*25+65),char(rand()*25+65));
return randomPass;
else
return "not_exist";
end if;
end //
DELIMITER //