title: What is the purpose of OUT in MySQL stored procedures?
body: <p>What is the purpose of <code>OUT</code> in MySQL stored procedures?</p>
  
  <p>If I have a simple stored procedure which looks like this:</p>
  
  <pre><code>DELIMITER $$
  
  CREATE DEFINER=`root`@`localhost` PROCEDURE `new_routine`(
      IN iID int
  )
  BEGIN
      select * from table1 where id = iID;
  END
  </code></pre>
  
  <p>This would give me all the results I want by running:</p>
  
  <pre><code>call new_routine(7);
  </code></pre>
  
  <p>So why would I want/need to use <code>OUT</code>?</p>
  
  <pre><code>DELIMITER $$
  
  CREATE DEFINER=`root`@`localhost` PROCEDURE `new_routine`(
      IN iID int,
      OUT vName varchar(100)
  )
  BEGIN
      select name into vName from table1 where id = iID;
  END
  </code></pre>
  
  <p>and call it like this</p>
  
  <pre><code>call new_routine(7, @name);
  select @name;
  </code></pre>
  
  <p>Which will give me just the name instead of everything from the rows returned?</p>
  
  <p>I've tried Googling, but clearly haven't asked Google the right question to get a clear answer.</p>