title: mysql stored function parameter
body: <p>I have just started to create a stored function this is my first time so I am having a few problems. Currently I call the function using <code>SELECT test();</code> (test is the function name for now). I want to send a number to the function (username ID) and have the username returned.</p>
  
  <p>I have this working by using <code>SELECT test(1);</code> 1 is the ID of a user in the table. This seems to work as the username is returned, but if I type in any number the same username is returned also.</p>
  
  <pre><code>BEGIN 
  
   DECLARE new_username VARCHAR(90);    
  
      SELECT `username` INTO  new_username FROM `users` WHERE `ID` = ID;
  
   return new_username;
  END
  </code></pre>
  
  <p>I have set the paramter as <code>ID int</code> .</p>
  
  <p>Am I right in thinking that the keyword <code>INTO</code> will put the value of the username into the variable <code>new_username</code> ? If I run it without the <code>INTO</code> I get the error:</p>
  
  <blockquote>
    <p>Not allowed to return a result set from a function</p>
  </blockquote>
  
  <p>Have I made any obvious mistakes in this, I hope I havent done it <em>totally</em> wrong. Thanks for any advice :).</p>
  
  <p><strong>Edit :</strong> I just added a few more rows into my table , I now get the error:</p>
  
  <blockquote>
    <p>Result consisted of more than one row</p>
  </blockquote>
  
  <p>Full sql version:</p>
  
  <pre><code>CREATE DEFINER=`elliotts`@`%` FUNCTION `test`(ID int) 
  RETURNS varchar(32) CHARSET latin1
  BEGIN 
  
      DECLARE new_username VARCHAR(32);
  
      SELECT `username` 
        INTO new_username 
        FROM `users` 
       WHERE `ID` = ID;
  
      return new_username;
  
  END
  </code></pre>