mbpakalin
mbpakalin

Reputation: 177

Oracle Long Raw Picture

I have a table named students and have columns named studentnumber, studentphoto(LONGRAW) and i need to export this longraw as jpeg.How can i do this?
I've searched everywhere but i can't find any solutions.
My Code:

Dim ImgWriter As New BinaryWriter(File.OpenWrite(outsideTxt.Text + "\" + flname))
            Dim ImgBlob(102400) As Byte
            Dim lBytesReturned As Long = 0, lStartIdx As Long = 0
            Dim buffersize As Integer
            buffersize = 4096
            lBytesReturned = x.GetBytes(0, lStartIdx, ImgBlob, 0, buffersize) ' The exception occurs here
            Do While (lBytesReturned = buffersize)
                ImgWriter.Write(ImgBlob)
                ImgWriter.Flush()
                lStartIdx = lStartIdx + buffersize
                lBytesReturned = x.GetBytes(0, lStartIdx, ImgBlob, 0, ImgBlob.Length)

                ImgWriter.Write(ImgBlob)
                ImgWriter.Flush()
                ImgWriter.Close()
            Loop

Note: column named photo is returning as null always. I tried in c# still same. How can i fix this ?

Upvotes: 2

Views: 1583

Answers (1)

Guido Leenders
Guido Leenders

Reputation: 4262

The Long raw datatype is something of the past and it was a mean construct to use. Long raw was for some time the only way to store a binary file in Oracle. You can access it using OCI, preferrably using Pro*C. But using Pro*C introduces an Oracle specific precompiler plus C. The precompiler is known to hard to upgrade over releases.

I would recommend the following approach:

In VB.Net use ODP.Net (if not yet already used) and execute query which casts the long raw to the modern blob, something like:

select to_lob(studentphoto) the_photo
from   students
where  studentnumber=250370

Then fetch the result of the_photo as you would do also with a varchar2.

If you need more sample, please put the table structure (DDL), an insert with some simple photo (may be just the raw string 'a') and information on the driver used in your question. Good luck!

Upvotes: 1

Related Questions