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 > Selecting a BLOB column in DB2 table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-22-10, 01:00
Springflower Springflower is offline
Registered User
 
Join Date: Feb 2010
Posts: 3
Selecting a BLOB column in DB2 table

I have a DB2 table column of type BLOB.
XML files are stored in this column.

I want to select this BLOB column in Enterprise Cobol (z/os) using a select statement.
I have declared the working-storage variable as follows:

01 MY-BLOB USAGE IS SQL TYPE IS BLOB(2M).

When I select the Blob column into MY-BLOB and display the data,
it displays non-readable characters.

How do I convert this BLOB into Charater data?

If this topic has already been discussed, please indiacate the corresponding thread.

Thank you for your help!
Reply With Quote
  #2 (permalink)  
Old 02-22-10, 01:44
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
You should define it as a CLOB, not a BLOB. A BLOB is for binary data and a CLOB is for character data.
__________________
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 02-22-10, 10:24
Springflower Springflower is offline
Registered User
 
Join Date: Feb 2010
Posts: 3
We cannot change it now as it is already in PROD.

I have a to find a way to convert BLOB to CLOB or other string type.

I appreciate any ideas from other members.

Thank you.
Reply With Quote
  #4 (permalink)  
Old 02-22-10, 13:58
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You could rename the table and add a view in its place that does the conversion. However, you'd need to write a UDF that takes the BLOB and copies the data to return it as CLOB. This is bound to be slow.

Another approach would be to adjust your application to accept the binary data and interpret it as string data. After all, its just a bunch of bytes.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 02-22-10, 13:59
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You could rename the table and add a view in its place that does the conversion. However, you'd need to write a UDF that takes the BLOB and copies the data to return it as CLOB. This is bound to be slow.

Another approach would be to adjust your application to accept the binary data and interpret it as string data. After all, its just a bunch of bytes.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 02-23-10, 14:22
Springflower Springflower is offline
Registered User
 
Join Date: Feb 2010
Posts: 3
Stolze,

Thanks for your reply. Based on your suggestion, I converted the binary data into EBCDIC from in the cobol program.

IBM - How to convert EBCDIC to ASCII or ASCII to EBCDIC in a COBOL Program?

How to convert EBCDIC to ASCII or ASCII to EBCDIC in a COBOL Program?

Question
Within an Enterprise COBOL for z/OS program, how do I convert an item described as PICTURE X, which is EBCDIC on the mainframe, to ASCII?

Cause
Use the FUNCTION NATIONAL-OF and FUNCTION DISPLAY-OF. It is necessary to first convert it to Unicode. In the following example, WS-CCSID must match the code page of the data.

Answer
This example is for Enterprise COBOL on z/OS, not for COBOL on AIX.
CBL DBCS,NSYMBOL(NATIONAL)
IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-AREA PICTURE N(50).
01 WS-CCSID PICTURE 9(5).
01 WS-ASCII PICTURE X(50).
01 WS-EBCDIC PICTURE X(50).
PROCEDURE DIVISION.
MOVE "ABCDE"
TO WS-EBCDIC.
DISPLAY " WS-EBCDIC = " WS-EBCDIC.
MOVE FUNCTION NATIONAL-OF(WS-EBCDIC)
TO WS-AREA.
DISPLAY " WS-AREA = " WS-AREA.
MOVE 819 TO WS-CCSID.
MOVE FUNCTION DISPLAY-OF(WS-AREA, WS-CCSID)
TO WS-ASCII.
DISPLAY " WS-ASCII = " WS-ASCII.
DISPLAY "Now let's convert that WS-ASCII back to EBCDIC".
MOVE FUNCTION NATIONAL-OF(WS-ASCII,819 )
TO WS-AREA.
DISPLAY " WS-AREA = " WS-AREA.
MOVE 1140 TO WS-CCSID.
MOVE FUNCTION DISPLAY-OF(WS-AREA, WS-CCSID)
TO WS-EBCDIC.
DISPLAY " WS-EBCDIC = " WS-EBCDIC.
STOP RUN.

The EBCDIC letters ABCDE are hex C1C2C3C4C5. They will be converted to hex 4142434445. Then the 4142434445 will be converted back to C1C2C3C4C5.

Thanks.
Reply With Quote
Reply

Tags
blob to clob, converting blob data, reading blob, selecting blob column

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