1

I'm trying to read some binary data from Oracle using the System.Data.OracleClient namespace in C# .NET.

How do I convert the data from the OracleBinary class value to an integer?

            OracleConnection conn = new OracleConnection("Data Source=database;User Id=me;Password=me;");
            OracleCommand cmd = new OracleCommand("Select * From SomeData.TableName WHERE vid = 4527", conn);
            conn.Open();

            OracleDataReader reader = cmd.ExecuteReader();
            try
            {
                while (reader.Read())
                {
                    OracleBinary obj = reader.GetOracleBinary(5);
                    // here....
                }
            }
            finally 
            {
                reader.Close();
            }

            cmd.Dispose();

            conn.Close();
            conn.Dispose();

In the documentation for this database the columns definition reads that the data type is LONG RAW and "The values stored in Binary Large OBject (BLOB) format."

I was expecting some integers (negative & positive) from the BLOB.

not sure if anyone can help as I'm not able to ask the administrator no longer (moved on). If anyone could point me in a direction I would much appreciated.

EDIT: Just to expand (I missed a bit of info) on what the blob contains:

A vector of position log values such that the first element is the first measured depth value, the second element is the first true vertical depth value, the third element is the first x offset, the fourth is the first y offset, the fifth is the second measred depth

Many Thanks Rob

2
  • Does the BLOB just contain an integer? Commented Apr 27, 2011 at 15:43
  • An array of bytes by the looks of it Commented Apr 27, 2011 at 15:56

1 Answer 1

1

How do I convert the data from the OracleBinary class value to an integer?

Here it is:

OracleBinary obj = reader.GetOracleBinary(5);
byte[] bytes = obj.Value;
int value = BitConverter.ToInt32(bytes);

But are you sure that's what you really want? Integer values are usually not stored in BLOBs... BLOBs are designed to contain arbitrary binary data, such as an image.

Sign up to request clarification or add additional context in comments.

2 Comments

just added some information if it even helps, that's all I got!
@rob, the information you added is important, but it's not enough... you need to know the actual type of the values in the blob to be able to read them. Are they integers or floating point numbers? What is their size?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.