【问题标题】:Mysql stored procedure If condition doesn't work [duplicate]Mysql存储过程如果条件不起作用[重复]
【发布时间】:2020-11-10 05:19:48
【问题描述】:

我有一个mysql存储过程来检查登录信息是否与我的数据库信息匹配

obs:我刚开始使用Mysql,所以这段代码可能有很多错误。

-表 1 - 函数 (email_func,senha)

-表 2 - Cliente (email_cli,senha_cli)

这是sp代码

delimiter %%
create procedure SpLogin(email varchar(100), senha varchar(15))
begin
declare c int;
declare f int;
begin
 if exists(select * from cliente where email_cli = email and senha_cli = md5(senha))
 then select 'c' as result;
 else set c = 0;
end if;
end;
begin
 if  exists (select * from funcionario where email_func = email and senha = senha)
 then select 'f' as result;
 else set f = 0; 
end if;
end;
begin
 if  (f = 0 and c = 0)
 then select '0' as result;
 end if;
 end;
end %%
delimiter ;

当我用这封电子邮件调用 sp 时,两个表中有一个相同的“电子邮件” 无论我写什么“senha”,它总是返回“f”作为结果。

【问题讨论】:

    标签: mysql sql database stored-procedures procedure


    【解决方案1】:

    您应该使用与表中的列名不同的名称来命名您的过程参数。

    where ... senha = senha
    

    senha 列必然等于同一行中的senha 列。

    MySQL不知道你的意思是第一个senha是列,第二个senha是过程参数。

    【讨论】:

    • 谢谢,成功了
    猜你喜欢
    • 2020-04-06
    • 2020-06-15
    • 2014-12-31
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    相关资源
    最近更新 更多