RohitR RohitR - 1 month ago 12
MySQL Question

MySQL procedure returns empty

Here is a very basic issue that i have and i assume it might be due to a syntax issues with MySQL sql.

Here is my procedure that i'm having trouble with

CREATE DEFINER=`test` PROCEDURE `get_users`(IN user_id INT)
BEGIN
select * from user where user_id = @user_id;
END


Calling the procedure as below

call test.get_users(1);


I have a user table with user_id values as '1' and i can see results when i use a select statement
select * from users;

Answer

i think the @ symbol is your problem. this works on my MySQL-DB

CREATE DEFINER=`codemagic.net.db`@`%` 
PROCEDURE `get_user`(IN `user_id` INT) 
NOT DETERMINISTIC READS SQL DATA SQL SECURITY DEFINER 
select * from users where id = user_id

regards

  • Marcel