title: Declaring and using MySQL varchar variables
body: <p>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 sure why... in any case I'm presumably confusing them/picking the wrong one/mixing them.</p>
  
  <p>Here's a minimal fragment that fails:</p>
  
  <pre><code>DECLARE FOO varchar(7);
  DECLARE oldFOO varchar(7);
  SET FOO = '138';
  SET oldFOO = CONCAT('0', FOO);
  
  update mypermits 
     set person = FOO 
   where person = oldFOO;
  </code></pre>
  
  <p>I've also tried wrapping it with BEGIN... END; and as a PROCEDURE.  In this case MySQL Workbench helpfully tells me: "SQL syntax error near ')'" on the first line and "SQL syntax error near 'DECLARE oldFOO varchar(7)'" on the second.  Otherwise it gives both lines as errors in full, with "SQL syntax error near ..." on both.</p>
  
  <p>Edit: I forgot to mention that I've tried it with and without @s on the variables.  Some resources had it with, others without.</p>
  
  <p>What dumb mistake am I making?</p>