MySQL stored procedure always getting empty values
I am very new to stored procedure. I am trying to write a very basic stored procedure. And here it is:
DELIMITER //
CREATE PROCEDURE `getname` (IN a_id INT, OUT a_name VARCHAR(50))
BEGIN
SELECT name INTO a_name FROM tblname WHERE id = a_id;
END //
DELIMITER ;
I have a very very simple database with a single table, a single rows in it with id 1 and a string value as name. Each time I call the procedure like:
CALL getname(1, @a_name);
SELECT @a_name;
it always returns NULL values :(
I am sitting for last 4 hours with this simple proble开发者_JS百科m but still no luck. Hope to get a solution from you guys.
BTW, I am using XAMPP 1.7.1 for windows 32 bit with MySQL version is 5.1.33.
Try in this session -
CALL getname(1, @a_name);
SELECT @a_name;
SELECT * FROM tblname WHERE id = 1; -- Is there any result?
If result is not empty, then try to run this SELECT statement from the procedure -
...
BEGIN
SELECT * FROM tblname WHERE id = 1;
END//
...
And call it again.
精彩评论