0

I am using MySQL v5.0.92 and I'm trying to import some data, but I get an error on declare my variables.

BEGIN
  DECLARE flag INT;
  DECLARE id INT;


while flag=0 begin
  SET id=(SELECT top 1 user_id 
         FROM ac_user_info WHERE user_id>@id order by user_id)

  INSERT INTO cuddleew_database1.cewp_usermeta(user_id,meta_key,meta_value)
  SELECT id,'first_name',first_name 
  FROM cuddleew_backup.ac_user_info WHERE user_id=@id

  INSERT INTO cuddleew_database1.cewp_usermeta(user_id,meta_key,meta_value)
  SELECT id,'last_name',last_name 
  FROM cuddleew_backup.ac_user_info WHERE user_id=@id

  SET flag=(select case @id when(SELECT MAX(user_id) 
                                FROM cuddleew_bakup.ac_user_info) then 1
     else 0
     END CASE)
  END WHILE
END

In MySQL console i get this:

BEGIN DECLARE flag INT;

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE flag INT' at line 2.

Can you help me with this and tell me what's wrong. Thanks in advance.

1 Answers1

1

You have to change your delimiter first, so the ; doesn't tell MySQL that this command is over.

DELIMITER $$

[your code here]

END $$

DELIMITER ;
user327961
  • 2,440
  • 3
  • 22
  • 20
  • I have added DELIMITER $$ [my code] END $$ DELIMITER; and I get an even bigger error. And my phpMyAdmin have delimiter option, and it's set to ";". – user3864506 Jul 22 '14 at 12:30