title: Pass binary to Oracle stored procedure using varchar2 in C#
body: <p>I have an Oracle Stored Procedure to calculate a checksum of a data block:</p>
  
  <pre><code>CalculateCheckSum( datablock in varchar2, result in out varchar2)
  </code></pre>
  
  <p>I have another C# procedure to get a 100 bytes data block and then call the stored procedure:</p>
  
  <pre><code>main()
  {
    string r;
    byte[] data = new byte[100];
    /* put something into data[] */
    r = getCheckSum(data, "/*a connect string*/");
  }
  
  
  string getCheckSum(byte[] data, string ConnStr)
  {
    string result;
    string datablock;
    using (OracleConnection conn = new OracleConnection(ConnStr))
    {
      conn.Open();
      datablock = Encoding.UTF8.GetString(data);
      OracleCommand cmd = new OracleCommand();
      cmd.Connection = conn;
      cmd.CommandText = "CalculateCheckSum";
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.Add("datablock", OracleDbType.Varchar2, 100, datablock, ParameterDirection.Input);
      cmd.Parameters.Add("result", OracleDbType.Varchar2, 8, "00000000", ParameterDirection.InputOutput);
      cmd.ExecuteNonQuery();
      result = cmd.Parameters["result"].Value.ToString();
      conn.Close();
    }
    return (result);
  }
  </code></pre>
  
  <p>I found that everything is OK if all the bytes of the data[] has value less than 128. Otherwise, the stored procedure will find that the length of datablock is more than 100.</p>
  
  <p>Can anyone solve the issue?</p>