If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 Blob

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-21-10, 15:07
nitingautam nitingautam is offline
Registered User
 
Join Date: Nov 2008
Location: Delhi, India
Posts: 15
DB2 Blob

Hi,

Is there any way to know whether the blob field is empty or it have some data in it?

I have to create a join, to find out all rows that have blob field is empty/nothing stored in it

Thanks,
Reply With Quote
  #2 (permalink)  
Old 12-21-10, 15:09
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Something "like":

select length(cast blob-col-name as VARCHAR(nnnn)) from table-name.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 12-21-10, 15:45
nitingautam nitingautam is offline
Registered User
 
Join Date: Nov 2008
Location: Delhi, India
Posts: 15
Quote:
Originally Posted by Marcus_A View Post
Something "like":

select length(cast blob-col-name as VARCHAR(nnnn)) from table-name.

i tried
Quote:
select length(cast(CT as VARCHAR(200))) from Content
and getting multiple rows with one column having '200' as value
Reply With Quote
  #4 (permalink)  
Old 12-21-10, 16:05
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
I said "something like." I expected you to figure out how to adapt it to your own needs, such as:

select * from Content WHERE length(cast(CT as VARCHAR(200))) = 0
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 12-22-10, 15:29
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The question is what "no data" really means. An empty BLOB could be interpreted like an empty string - it is well-defined information, which is different from NULL. So if "no data" means "is there a value or is it NULL", you would use a predicate "blob-column IS [NOT] NULL". If you are interested in BLOBs that have a size of 0, simply use the LENGTH function as in "LENGTH(blob-column) = 0".

p.s: You cannot cast a BLOB to a VARCHAR. One is binary data, the other is string data (with code page, yada yada...).
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 12-22-10, 20:58
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by stolze View Post
p.s: You cannot cast a BLOB to a VARCHAR. One is binary data, the other is string data (with code page, yada yada...).
According to the OP he was able to do it, if understand his post above correctly. I haven't tried it myself.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #7 (permalink)  
Old 12-28-10, 10:54
JAYANTA_DATTA JAYANTA_DATTA is offline
Registered User
 
Join Date: Oct 2004
Location: DELHI INDIA
Posts: 336
Yes, to find the BLOB without anything stored in it is considered as NULL ( as you correctly mentioned above). To find out the length of the particular Blob field in each row, it shows the length of the string which is considered the link of the location of the Blob image. For finding the actual size of each BLOB image, you can add an additional field in your table which will store the image size during the time of insert only with the help of the API / application loading the blob files.
__________________

Jayanta Datta
DB2 UDB DBA
IBM India, Global Delivery
New Delhi
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On