title: MySQL - Trouble with creating user defined function (UDF)
body: <p>I'm trying to create this function:</p>
  
  <pre><code>CREATE FUNCTION remove_non_alphanum (prm_strInput varchar(3000))
  RETURNS VARCHAR(3000)
  DETERMINISTIC
  
  BEGIN
  
    DECLARE i INT DEFAULT 1;
    DECLARE v_char VARCHAR(1);
    DECLARE v_parseStr VARCHAR(3000) DEFAULT '';
  
    WHILE (i &lt;= LENGTH(prm_strInput) )  DO
      SET v_char = SUBSTR(prm_strInput,i,1);
  
      IF v_char REGEXP '^[A-Za-z0-9]$' THEN
        SET v_parseStr = CONCAT(v_parseStr,v_char);  
      END IF;
  
      SET i = i + 1;
    END WHILE;
  
    RETURN trim(v_parseStr);
  END
  </code></pre>
  
  <p>But MySQL says:</p>
  
  <blockquote>
    <p>13:52:45  [CREATE - 0 row(s), 0.000 secs]  [Error Code: 1064, SQL State: 42000]  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 '' at line 5</p>
  </blockquote>
  
  <p>What could I being wrong?  The syntax looks correct to me.</p>