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 > Functions to manipulate BLOB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-15-05, 04:19
ggnanaraj ggnanaraj is offline
Registered User
 
Join Date: Aug 2002
Location: Chennai, India
Posts: 171
Functions to manipulate BLOB

DB2 UDB v7.2

Given a table data that also contains BLOB, can we use functions to edit the contents of the BLOB based on a search condition on the same BLOB data?

Example:

db2 describe table blobtab

id integer
stats BLOB


Now, the SQL...

update blobtab set stats= <something> where stats = <something>

TIA.
Reply With Quote
  #2 (permalink)  
Old 12-16-05, 02:22
gardenman gardenman is offline
Registered User
 
Join Date: Apr 2004
Posts: 54
do like this:

update blobtab set stats= blob('Here is new text')
where stats = blob('Here is oldtext')

or like this:

update blobtab set stats= blob(x'01234567890ABCDEF0')
where stats = blob(x'0E1F')

x'65' - is hexadecimal representation of character 'A'
Reply With Quote
  #3 (permalink)  
Old 12-16-05, 08:29
ggnanaraj ggnanaraj is offline
Registered User
 
Join Date: Aug 2002
Location: Chennai, India
Posts: 171
Quote:
Originally Posted by gardenman
do like this:

update blobtab set stats= blob('Here is new text')
where stats = blob('Here is oldtext')

or like this:

update blobtab set stats= blob(x'01234567890ABCDEF0')
where stats = blob(x'0E1F')

x'65' - is hexadecimal representation of character 'A'

Thanks for the input.

Can you execute the following and see as I'm gettting SQL0408N error.

Code:
db2 "create table blobtab(id integer, stats BLOB(1048576))"
db2 "insert into blobtab values(1, '65')"
Reply With Quote
  #4 (permalink)  
Old 12-19-05, 07:08
gardenman gardenman is offline
Registered User
 
Join Date: Apr 2004
Posts: 54
use:
db2 "insert into blobtab values(1, blob('65'))"
Reply With Quote
  #5 (permalink)  
Old 12-19-05, 07:38
ggnanaraj ggnanaraj is offline
Registered User
 
Join Date: Aug 2002
Location: Chennai, India
Posts: 171
Quote:
Originally Posted by gardenman
use:
db2 "insert into blobtab values(1, blob('65'))"
Thanks again, it works... However, when trying to update what I've just inserted it fails!

Code:
$ db2 "insert into blobtab values(1, blob('75'))"
DB20000I  The SQL command completed successfully.
Code:
$ db2 "update blobtab set stats=blob('85') where stats = blob('75')"
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0401N  The data types of the operands for the operation "=" are not
compatible.  SQLSTATE=42818

Code:
$ db2 "update blobtab set stats= blob('95') where stats = blob(x'3735')"
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0401N  The data types of the operands for the operation "=" are not
compatible.  SQLSTATE=42818
TIA.
Reply With Quote
  #6 (permalink)  
Old 12-20-05, 04:28
gardenman gardenman is offline
Registered User
 
Join Date: Apr 2004
Posts: 54
you cannot specify blob field in predicate.

do like this:

create table xxx (
id int,
note blob(10K)
)

insert into xxx values (1,blob('xxxxxxxx'))

update xxx set note='yyyyy' where id=1
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