469,306 Members | 2,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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

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
1 12058
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.

Similar topics

2 posts views Thread by Carolyn Longfoot | last post: by
3 posts views Thread by Selen | last post: by
2 posts views Thread by martin | last post: by
4 posts views Thread by cuyler.jones | last post: by
4 posts views Thread by Connie | last post: by
16 posts views Thread by wizard | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.