But when the content of the table is checked from SQL it appears to be incorrect Any characters > 0x7F appear as DF
C:\Program Files\IBM\SQLLIB\BIN>db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 11.5.4.0
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 => select * from DB2INST1.BLOB_TAB
ID B1
----------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 x'000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7FFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFD'
1 record(s) selected.
db2 =>
The only workaround I can find is to pass the data in a CLOB as HEX and use a custom SQL PL procedure to convert back to a BLOB. This leads to poor performance with any significant volume of data.
CREATE OR REPLACE FUNCTION YADAMU.HEXTOBLOB (HEX_VALUE CLOB(16M))
RETURNS BLOB(16M)
DETERMINISTIC
NO EXTERNAL ACTION
CONTAINS SQL
BEGIN
DECLARE RAW_VALUE BLOB(16M);
DECLARE HEX_LENGTH BIGINT;
DECLARE OFFSET BIGINT;
DECLARE HEX_CHUNK VARCHAR(32672);
DECLARE RAW_CHUNK BLOB(16336);
IF (HEX_VALUE is NULL) THEN
return NULL;
END If;
SET HEX_LENGTH = LENGTH(HEX_VALUE);
SET OFFSET = 1;
SET RAW_VALUE = EMPTY_BLOB();
WHILE (OFFSET <= HEX_LENGTH) DO
SET HEX_CHUNK = SUBSTR(HEX_VALUE,OFFSET,32672);
SET HEX_CHUNK = TRIM(TRAILING FROM HEX_CHUNK);
SET RAW_CHUNK = HEXTORAW(HEX_CHUNK);
SET OFFSET = OFFSET + LENGTH(HEX_CHUNK);
SET RAW_VALUE = RAW_VALUE CONCAT RAW_CHUNK;
END WHILE;
RETURN RAW_VALUE;
END;
/
Running the following code
Generates the following output
But when the content of the table is checked from SQL it appears to be incorrect Any characters > 0x7F appear as DF
The only workaround I can find is to pass the data in a CLOB as HEX and use a custom SQL PL procedure to convert back to a BLOB. This leads to poor performance with any significant volume of data.