473,856 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

This is my TABLE:
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?



Nov 12 '05 #1
1 14573
Markus wrote:
This is my TABLE:
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

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); $blob=mysql_fetch_assoc($result); Now when I do print_r (array_values($blob));
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 ? I'm getting an AbstractMethodError suggesting that the DB2 driver I'm using didn't implement setBinaryStream. I can update the Blob without writing to an OutputStream, but I'm migrating a lot of code from Oracle and I'd perfer
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. How can I do this?
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 the syntax
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 characters and stops at the first non-character element. Any attempt to alter the field type using VB.NET is not allowed. Casting the data generates an invalid cast exception. Therefore, it is not clear how to extract binary large objects from a...
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 when the page loads, it just spews the binary garbage rather than displaying the image. Here's the code:
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 retrieved byte/binary data as i got no idea on how to save them in our pc. For this situation, what i need to do is give the byte/binary data an extension (retrieved from another field in the table) in order to revert back to the original data i had in the...
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 is happening, if I run it as below I get 23736000 for a result. select sum(datalength (cast(document AS binary(8000)))) from plan_report If I run it like this select sum(datalength (cast(document AS varbinary(8000)))) from plan_report
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 code to read a blob from DB I am not having any luck, I am running this java programs using JDEVELOPER. Can anyone please give me some help? The code is as follows: ... private static byte getBytesFromBlob(Blob blob) throws Exception { ...
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 #include <stdlib.h> #include <stdio.h>
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.