Variable returning null value

2

I am creating a procedure for storing the food name in the food variable of the procedure, follow the code:

DELIMITER $$
CREATE PROCEDURE armazena_nome(id INT, OUT alimento VARCHAR(20))
BEGIN
    SELECT alimentos_dados.nome_alimento INTO alimento FROM alimentos_dados WHERE alimentos_dados.id_alimento = id;
END $$
DELIMITER ;

When I make code below after making the "CALL" in the procedure it should return the food name but returns null:

SELECT @alimento

What am I doing wrong?

    
asked by anonymous 17.12.2017 / 20:10

1 answer

0

Make sure you are correctly calling the procedure:

SET @id = 1;
CALL armazena_nome(@id,@alimento);
SELECT @alimento;
    
25.03.2018 / 20:01