[英]store function creation error in mysql #1064
I tried to create one function, ie if username exist, will return random number and character as a single string, but I tried below code, throwing syntax error like below, can u help to find the issue, I know that having issue in declaring string and returning string, but unable to find the issue. 我试图创建一个函数,即如果用户名存在,它将以单个字符串的形式返回随机数和字符,但是我尝试了下面的代码,并抛出如下所示的语法错误,您能帮忙找到问题吗,我知道声明时有问题字符串和返回的字符串,但找不到问题。 Thanks to the replies in advance
感谢提前的答复
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 - You have an error in your SQL syntax; #1064-您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select concat( char(round(rand()*36)+1), char(round(rand()*36)+1), char(round(ra' at line 6
检查与您的MySQL服务器版本相对应的手册以获取正确的语法以在'select concat(char(round(rand()* 36)+1),char(round(rand()* 36)+1),char (第6行的回合(ra'
You are missing a closing )
on this line: 您在此行上缺少
)
:
SELECT @randomPass := select concat( char(round(rand()*36)+1), char(round(rand()*36)+1), char(round(rand()*36)+1);
should be 应该
SELECT @randomPass := select concat( char(round(rand()*36)+1), char(round(rand()*36)+1), char(round(rand()*36)+1));
Hooray, finally found answers.. This below code will help to solve the solution Hooray,终于找到了答案。.下面的代码将帮助解决问题的解决方案
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 //
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.