title: MySQL select in function
body: <p>I'm trying to write a MySQL function with a select inside, but always get a NULL return</p>
  
  <pre><code>CREATE FUNCTION test (i CHAR)
  RETURNS CHAR
  NOT DETERMINISTIC
  BEGIN
  DECLARE select_var CHAR;
  SET select_var = (SELECT name FROM table WHERE id = i);
  RETURN select_var;
  END$$
  
  mysql&gt; SELECT test('1')$$
  +-----------------+
  |    test('1')    |
  +-----------------+
  | NULL            | 
  +-----------------+
  1 row in set, 1 warning (0.00 sec)
  
  mysql&gt; 
  mysql&gt; 
  mysql&gt; SHOW WARNINGS
      -&gt; $$
  +---------+------+----------------------------------------+
  | Level   | Code | Message                                |
  +---------+------+----------------------------------------+
  | Warning | 1265 | Data truncated for column 'i' at row 1 | 
  +---------+------+----------------------------------------+
  1 row in set (0.00 sec)
  </code></pre>