I noticed that the select statement inside my stored procedure always returns the same value, regardless of the parameter with which I call my stored procedure. Here is the code:
DELIMITER $$
CREATE PROCEDURE TEST(IN id INT)
BEGIN
DECLARE x INT DEFAULT 0;
select id;
SELECT paper_id
INTO x
FROM Paper
WHERE ID = id
limit 1;
select x;
END$$
x always returns the same value no matter what identifier I call the test with. I noticed that the x value is always the paper_id value in the front row of my Paper table.
However, if I run the same query outside the stored procedure, I get the expected value.
What happens inside a stored procedure that distorts this value?
source
share