MySQL - 存储过程返回意外值

时间:2023-02-02 16:38:32

I wrote a stored procedure(MySQL) that should return all user's data by user's email. Here is my stored procedure:

我写了一个存储过程(MySQL),应该通过用户的电子邮件返回所有用户的数据。这是我的存储过程:

-- Change Delimiter
DELIMITER //
-- Create Stored Procedure
CREATE DEFINER=`username`@`localhost` PROCEDURE GetUserByEmail( 
    IN Email VARCHAR(255)
)
BEGIN

SELECT * FROM user WHERE email = Email;

END//
-- Change Delimiter again
DELIMITER ;

However, instead of returning all data only for the user with specified email, it returns all user table. And when I run the same query without stored procedure it returns only data for the user with specified email. Here is the query:

但是,它不是仅为具有指定电子邮件的用户返回所有数据,而是返回所有用户表。当我在没有存储过程的情况下运行相同的查询时,它仅返回具有指定电子邮件的用户的数据。这是查询:

SELECT * FROM user WHERE email = 'username@email.com';

1 个解决方案

#1


1  

That´s because email it´s allways = to Email (the column names are not case sensitive) You should change it to something like this:

这是因为电子邮件是allways = to Email(列名不区分大小写)您应该将其更改为以下内容:

-- Change Delimiter
DELIMITER //
-- Create Stored Procedure
CREATE DEFINER=`username`@`localhost` PROCEDURE GetUserByEmail( 
    IN My_email VARCHAR(255)
)
BEGIN

SELECT * FROM user WHERE email = My_email;

END//
-- Change Delimiter again
DELIMITER ;

#1


1  

That´s because email it´s allways = to Email (the column names are not case sensitive) You should change it to something like this:

这是因为电子邮件是allways = to Email(列名不区分大小写)您应该将其更改为以下内容:

-- Change Delimiter
DELIMITER //
-- Create Stored Procedure
CREATE DEFINER=`username`@`localhost` PROCEDURE GetUserByEmail( 
    IN My_email VARCHAR(255)
)
BEGIN

SELECT * FROM user WHERE email = My_email;

END//
-- Change Delimiter again
DELIMITER ;