I\'m trying to do some simple manipulations with variables in MySQL 5.0 but I can\'t quite get it to work. I\'ve seen many (very!) different syntaxen for DECLARE/SET, I\'m not
I ran into the same problem using MySQL Workbench. According to the MySQL documentation, the DECLARE
"statement declares local variables within stored programs." That apparently means it is only guaranteed to work with stored procedures/functions.
The solution for me was to simply remove the DECLARE
statement, and introduce the variable in the SET
statement. For your code that would mean:
-- DECLARE FOO varchar(7);
-- DECLARE oldFOO varchar(7);
-- the @ symbol is required
SET @FOO = '138';
SET @oldFOO = CONCAT('0', FOO);
UPDATE mypermits SET person = FOO WHERE person = oldFOO;