Read BLOB data from oracle through a stored procedure

Posted on 2009-12-29
Last Modified: 2012-08-13
I have a column with blob data type in the oracle data base. i wrote a stored procedure which take an id value as in parameter and give blob value as out parameter.
From .net side i use the following code

OracleConnection conn = new OracleConnection(connnectionstring);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = procedure;
            cmd.Parameters.Add("SEQ_NO", OracleType.VarChar).Value = key;
            cmd.Parameters.Add("FILE_DATA", OracleType.Blob).Direction = ParameterDirection.Output;

            filedata = (byte[])cmd.Parameters["FILE_DATA"].Value;
            return filedata;

Its giving me error that it con not convert oraclelob to byte[].
Any ideas please
Question by:psdeepu545
    LVL 9

    Accepted Solution

    Hi psdeepu545,

    I modified your code based on the example at
    (the code is not tested)

    // Cast BLOB data using OracleBlob type
    OracleBlob blob = (OracleBlob)cmd.Parameters["FILE_DATA"].Value;
    // Create a byte array of the size of the Blob obtained
    Byte[] filedata =  new Byte[blob.Length];
    // Read blob data into byte array
    return filedata;

    Open in new window


    Author Comment

    There is no oracleblob class actually. i used dataset to get the blob and filled with dataadapter.
    by default when blob is stored in dataset it will store as a byte array.
    LVL 9

    Expert Comment

    You may download the Oracle 11g ODAC with Oracle Developer Tools for Visual Studio:

    Then, you can include this line in your class:

     using Oracle.DataAccess.Types;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now