0

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 = '[email protected]';

1 Answer 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:

-- 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 ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.