MySQL-存储过程返回意外值 [英] MySQL - stored procedure returns unexpected value
本文介绍了MySQL-存储过程返回意外值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个存储过程(MySQL
),该存储过程应该通过用户的电子邮件返回所有用户的数据.这是我的存储过程:
I wrote a stored procedure(MySQL
) that should return all user's data by user's email. Here is my stored procedure:
-- 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';
推荐答案
这是因为电子邮件始终=发送至电子邮件(列名不区分大小写),您应将其更改为以下形式:
That´s because email it´s allways = to Email (the column names are not case sensitive) You should change it to something like this:
-- 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 ;
这篇关于MySQL-存储过程返回意外值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文