title: MySQL- Stored Procs- Weirdness when trying to use an output parameter
body: <p>To be honest, I'm feeling pretty stupid right now.  But this simply <em>isn't working</em>.</p>
  
  <p><strong>Scenario</strong><br>
  I have a stored procedure that includes an output parameter.  I'm trying to SELECT a value INTO that parameter.  This seems simple, but it continues giving me faulty results.  I've checked many online sources, and I'm certain that I'm trying to do it properly.
  <br/><br/><br/>
  <strong>Code</strong></p>
  
  <pre><code>DELIMITER //
  CREATE PROCEDURE `spGetId`(
      IN ParamA VARCHAR(32),
      OUT OutputId INT
  )
  BEGIN
      SELECT `id` INTO OutputId
      FROM `Table`
      WHERE `column_a` = ParamA;
  END//
  
  CALL spGetId('foobar', @Bloop)//
  SELECT @Bloop//
  </code></pre>
  
  <p><br/>
  <strong>Results</strong><br>
  I have two rows in this table, their IDs being '1' and '2'.  The result I get back is '31', whether the SELECT statement matches anything or not.
  I have tried many variations, including removing the WHERE clause entirely and having the SELECT return a COUNT(1) into the parameter (which gives me a result of '32', despite there being only 2 rows), and I have tried "declaring" the @Bloop variable before using it in the sproc call by using <code>SET @Bloop = 0</code>.</p>
  
  <p>If you have any insight on why this is happening, and what I can do to make it return the proper value, I would be much obliged.  Also, if you can show me how to achieve the same desired result using a Stored <em>Function</em> instead, with a return value, I'd appreciate that even <em>more</em>!  My desired approach is using a stored function, but I had similar problems with that, then gave up and tried using a stored proc, only to find I was getting similar results.</p>
  
  <p>Anything you can offer would be helpful!</p>
  
  <p><em><strong>Edit</em></strong>:</p>
  
  <pre><code>CREATE TABLE `Table` (
   `id` int(11) NOT NULL auto_increment,
   `column_a` varchar(32) character set utf8 NOT NULL,
   PRIMARY KEY  (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  
  mysql&gt; SELECT * FROM Table;
  +------+----------+
  | id   | column_a |
  +------+----------+
  |    1 | asdf     |
  |    2 | foobar   |
  +------+----------+
  </code></pre>
  
  <p>When I call spGetId() with <em>any</em> argument, it returns the value '31' (even if the argument is 'foobar', which should return an integer value of '2' (or ascii 0x32)).  If I modify spGetId() to return the total rowcount of Table, instead of returning '2', it returns '32'.</p>