Mysql 存储过程如果条件不工作

Mysql stored procedure If condition doesn't work

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

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

-Table 1 - 函数 (email_func,senha)

-Table 2 - 客户 (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 ;

有一个 'email' 在两个表中是相同的,当我用这个电子邮件调用 sp 结果总是 return 'f' 不管我写什么 'senha'。

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

where ... senha = senha

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

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