title: mysql stored function - in varchar and return varchar - Error : 1172
body: <p>I could not figure out what went wrong with my stored function.</p>
  
  <pre><code>select batch as bach from test where mfg_code = 'BC-7A1-5' group by batch;
  </code></pre>
  
  <p>When I run the script above and I am able to get the number of rows as expected.</p>
  
  <p>However I am not able with the similar script below:-</p>
  
  <pre><code>DELIMITER $$
  DROP FUNCTION IF EXISTS `testdata1970_05`.`listbatch` $$
  CREATE FUNCTION `listbatch`(mfgnum VARCHAR(24)) RETURNS VARCHAR(10)
  
  BEGIN
  DECLARE bach VARCHAR(10);
  SELECT batch into bach FROM test WHERE mfg_code = mfgnum group by batch;
  RETURN bach;
  END $$
  
  DELIMITER ;  
  </code></pre>
  
  <p>And it returns error:</p>
  
  <blockquote>
    <p>"ERROR 1172 (42000): Result consisted of more than one row"</p>
  </blockquote>
  
  <p>And here is my query below:</p>
  
  <pre><code>select listbatch("BC-7A1-5");
  </code></pre>