简体   繁体   中英

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; 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

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

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 //

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM