Variable returning null value

Asked

Viewed 26 times

2

I’m creating a precedent for it to store the food name in the Procedure food variable, 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 code below after making "CALL" in the past it should return the food name but returns null:

SELECT @alimento

What am I doing wrong ?

  • Put the steps you created and called this procedure?

1 answer

0

Make sure you are calling the Precedent correctly:

SET @id = 1;
CALL armazena_nome(@id,@alimento);
SELECT @alimento;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.