title: Using variables as OFFSET in SELECT statments inside mysql's stored functions
body: <p>I'm quite new to subject of writting stored function for mySQL database, hence i'm not sure if what i'm trying to do here is possible at all. </p>
  
  <p>I need a function that will return a column from random row from a table. I don't want to use ORDER BY RAND() method to do that, rather i would do this like this:</p>
  
  <pre><code>DECLARE MAX_COUNT INT DEFAULT 120000;
  DECLARE rand_offset INT;
  DECLARE str_rnd_word VARCHAR(255);
  SET rand_offset = FLOOR((RAND() * MAX_COUNT));
  
  SELECT word INTO str_rnd_word FROM all_words LIMIT 1 OFFSET rand_offset ;
  
  RETURN str_rnd_word;
  </code></pre>
  
  <p>MySQL throws an error upon creating function with body like that. But when I use hard-coded number as OFFSET it works just fine.</p>
  
  <p>Can someone shed some light on the subject please.</p>
  
  <p>I'm running MySQL 5.0.45 on windows box.</p>
  
  <p>Thanks</p>