473,383 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 14420
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Carolyn Longfoot | last post by:
Help! This is driving me crazy... I'm trying to read a BLOB from a db and display it in a browser, like so: $query="SELECT blob from table where blob_id=9"; $result=mysql_query($query);...
1
by: gimme_this_gimme_that | last post by:
In DB2, is it possible to update a table having a BLOB using a statement such as "SELECT MY_BLOB_FIELD FROM MY_TABLE FOR UPDATE" Then getting the Blob and writing to the Blob's output stream ? ...
3
by: Selen | last post by:
I would like to be able to extract a BLOB from the database (SqlServer) and pass it to a browser without writing it to a file. (The BLOB's are word doc's, MS project doc's, and Excel spreadsheets....
2
by: martin | last post by:
Hi, I have blob field in my database. I am retrieveing the field through a stored procedure and the execute scalar method. I would like to cast resulting "byte" field to a string. I am using...
0
by: Wayne | last post by:
A field within a FoxPro database typed as a BLOB is reported as s System.String when accessed using Vb.Net. Attempting to fetch the binary data into a .NET string fetches only the first few...
4
by: cuyler.jones | last post by:
Hello -- I'm having a heck of a time grabbing a blob ( a jpeg image) from a mySQL database and displaying it on a page. I am able to connect to the database and retrieve the data, however...
2
by: Vinciz | last post by:
hi guys... im new in java and i would love to learn some of these... basically i got a sample code to retrieve the blob from the mysql. however, i dont really know what to do with these...
4
by: Connie | last post by:
I have a column in my table that is an Image (blob). The data stored in this blob is basically pdf files. I need a query to determine the total size of these blob's in the database. Here is what...
4
by: skunapareddy | last post by:
I am needing to read a blob from database and pass it to another java program. I researched internet and found a program that reads a file on the client pc and gives bytes, but when I modified the...
16
by: wizard | last post by:
Here is a piece of code below for writing and reading blobs in SQLITE database. I ' ve a problem to read from blob struct called 'Points' Any help would be appreciated Reagards Greg ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.