skip to Main Content

I’m trying to create a stored procedure in phpmyadmin but when I try to create a second one, I get the error

#1327 – Undeclared variable.

This works fine:

BEGIN
    DECLARE id_pro INT(9);
    SELECT user_product_id INTO id_pro FROM usuario;
END

But if I want to add another variable, I get the error above:

BEGIN
    DECLARE id_pro INT(9);
    DECLARE date_product datetime;
    SELECT user_product_id INTO id_pro, date_pro INTO date_product FROM usuario;
END

It doesn’t detect date_product variable.

2

Answers


  1. To assign INTO several variables, use the following syntax:

    SELECT user_product_id, date_pro INTO id_pro, date_product FROM usuario;
    

    See the MySQL SELECT ... INTO syntax.

    Login or Signup to reply.
  2. Or don’t use INTO:

    SELECT id_pro := user_product_id, date_product := date_pro 
    FROM usuario;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search