title: Oracle - Getting Select Count(*) from ... as an output parameter in System.Data.OracleClient
body: <p>Greetings all, </p>
  
  <p>I have a question.  I am trying to build a parametrized query to get me the number of rows from a table in Oracle.  Rather simple.  However I am an Oracle newbie..</p>
  
  <p>I know in SQL Server you can do something like:</p>
  
  <p><code>Select @outputVariable = count(*) from sometable where name = @SomeOtherVariable</code></p>
  
  <p>and then you can set up an Output parameter in the System.Data.SqlClient to get the @outputVariable.</p>
  
  <p>Thinking that one should be able to do this in Oracle as well, I have the following query</p>
  
  <p><code>Select count(*) into :theCount from sometable where name = :SomeValue</code></p>
  
  <p>I set up my oracle parameters (using System.Data.OracleClient - yes I know it will be deprecated in .Net 4 - but that's what I am working with for now) as follows</p>
  
  <pre><code>IDbCommand command = new OracleCommand();
  command.CommandText = "Select count(*) into :theCount from sometable where name = :SomeValue";
  command.CommandType = CommandType.Text;
  
  OracleParameter parameterTheCount = new OracleParameter(":theCount", OracleType.Number);
  parameterTheCount .Direction = ParameterDirection.Output;
  command.Parameters.Add(parameterTheCount );
  
  OracleParameter parameterSomeValue = new OracleParameter(":SomeValue", OracleType.VarChar, 40);
  parameterSomeValue .Direction = ParameterDirection.Input;
  parameterSomeValue .Value = "TheValueToLookFor";
  command.Parameters.Add(parameterSomeValue );
  command.Connection = myconnectionObject;
  command.ExecuteNonQuery();
  int theCount = (int)parameterTheCount.Value;
  </code></pre>
  
  <p>At which point I was hoping the count would be in the parameter <code>parameterTheCount</code>  that I could readily access.</p>
  
  <p>I keep getting the error ora-01036 which <a href="http://ora-01036.ora-code.com" rel="nofollow noreferrer">http://ora-01036.ora-code.com</a> tells me to check my binding in the sql statement.  Am I messing something up in the SQL statement?  Am I missing something simple elsewhere?</p>
  
  <p>I could just use command.ExecuteScaler() as I am only getting one item, and am probably going to end up using that, but at this point, curiosity has got the better of me.   What if I had two parameters I wanted back from my query (ie: select max(ColA), min(ColB) into :max, :min.....)</p>
  
  <p>Thanks..</p>