By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,586 Members | 2,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,586 IT Pros & Developers. It's quick & easy.

How can I cast a BLOB-value to a VARCHAR-value?

P: n/a
This is my TABLE:
CREATE TABLE test(
data BLOB
)

This is my INSERT:
INSERT INTO test(data) VALUES (CAST('I am a test' AS BLOB))

But how can I SELECT the data as VARCHAR, so that I can see "I am a
test" instead of BLOB-value?

Greetings

Markus

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Markus wrote:
This is my TABLE:
CREATE TABLE test(
data BLOB
)

This is my INSERT:
INSERT INTO test(data) VALUES (CAST('I am a test' AS BLOB))

But how can I SELECT the data as VARCHAR, so that I can see "I am a
test" instead of BLOB-value?


Given that BLOBs contain binary data - that's the first 'B' - you have to
write your own function to do such a conversion.

Note that any byte in the binary data could be 0x00, and that's the
end-of-string character in C/C++, effectively truncating all the data after
that byte if you would just take binary data and treat it like a string.
(Other questions like non-printable characters and such are yet another
issue with binary vs. string data.)

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.