首页 文章

Mysql在函数中截断了不正确的DOUBLE值

提问于
浏览
0

我搜索并知道这已被多次询问,但我的看似不同 . 我不是在使用 update 也不是 and . 由于以下测试,我称之为"in function",我真的很困惑 .

功能:

drop function if exists `login_t`;
create function `login_t`()
returns bool
begin
    declare `pw` varchar(32);
        set `pw` = '4297f44b13955235245b2497399d7a93';
    return if(pw, pw = MD5(CONCAT('123', '123')), false);
end;
select login_t(); -- > Truncated incorrect DOUBLE value: '4297f44b13955235245b2497399d7a93'

在proc中:

drop procedure if exists `login_t2`;
create procedure `login_t2`()
begin
    declare `pw` varchar(32);
        set `pw` = '4297f44b13955235245b2497399d7a93';
    select if(pw, pw = MD5(CONCAT('123', '123')), false);
end;
call login_t2(); -- 1

1 回答

  • 0

    看起来当您从函数返回布尔值时,值应为数字 . MySQL尝试将if函数(pw)的第一个参数转换为数值并失败 .

    你可以使用代码:

    create function `login_t`()
    returns boolean
    begin
        declare `pw` varchar(32);
    
        set `pw` = '4297f44b13955235245b2497399d7a93';
    
        if (pw = MD5(CONCAT('123', '123'))) then
          return true;
        else   
          return false;
        end if;
    end;
    

相关问题