簡體   English   中英

在mysql#1064中存儲函數創建錯誤

[英]store function creation error in mysql #1064

我試圖創建一個函數,即如果用戶名存在,它將以單個字符串的形式返回隨機數和字符,但是我嘗試了下面的代碼,並拋出如下所示的語法錯誤,您能幫忙找到問題嗎,我知道聲明時有問題字符串和返回的字符串,但找不到問題。 感謝提前的答復

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 (第6行的回合(ra'

您在此行上缺少)

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

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM