Link to home
Start Free TrialLog in
Avatar of lmpsteelwire
lmpsteelwireFlag for United States of America

asked on

converting BLOB to String

hey guys, I need a select statement that convert a blob, and bring me back a string

i know for sure, everytime, that the blob is just plain old text. Is there anyway to do that?
Avatar of JanMah
JanMah

Hi

Do you want to convert BLOB to string in oracle itself or in a programming language (VB ..)?
Avatar of lmpsteelwire

ASKER

Either oracle or VB.net....but if vb.net, im using oracleclient dll
OK

Here is one of the VB solutions to convert BLOB to string.

After getting the BLOB from the oracle

Dim sAns As String
Dim iPos As String
   
sAns = StrConv(GetAttachment, vbUnicode) ' GetAttachment is BLOB
iPos = InStr(sAns, Chr(0))
If iPos > 0 Then sAns = Left(sAns, iPos - 1)
   
GetAttachment = sAns

Hope this helps.

JanMah
im using vb.net, not vb
well i am sure you can change it to .Net, you can't expect all as piece of cake, huh?

JanMah
I could convert it...

but I dont know how to bring a blob in from the database to my vb/vb.net
OK.. here we go

The SQL will be

Select * from TableName where ID = <ID>

Nothing special here.

After getting it in recordset, use

Dim sAns As String
Dim iPos As String
Dim bGetAttachment as Byte()

bGetAttachment = rs("Attachment").GetChunk(rs("Attachment").ActualSize)

   
sAns = StrConv(bGetAttachment, vbUnicode) ' GetAttachment is BLOB
iPos = InStr(sAns, Chr(0))
If iPos > 0 Then sAns = Left(sAns, iPos - 1)
   
GetAttachment = sAns


janMah
StrConv wont take a byte array.
well, it will take. Have you checked it?
nevermind. I used another question on EE to answer that last part...thanks man.


is inserting a string back into oracle as a blob just the same?
yes, if you want to just strore the string just because, it is more than 4000 char long, then I would suggest you to go for clob.

If you want to strore a file (eg. excel/image) to keep the format, then go for blob.

JanMah
how exactly can i insert it back into the database? I cant insert a byte()

is there another method i have to do?
ASKER CERTIFIED SOLUTION
Avatar of JanMah
JanMah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial