How to convert String to BLOB in ESQL?

6.7k views Asked by At

It should be as simple as

  SET OutputRoot.BLOB.BLOB = CAST(MYSTRING AS BLOB);

But when I do that IIB Throws an error

An attempt was made to cast the character string ''ABC'' to a byte string, but the string was of the wrong format. There must be an even number of hexadecimal digits (0-9, a-f, A-F).

2

There are 2 answers

0
DThompson55 On

In my case I needed to change it to AS BLOB CCSID 1208 I need to read up on what CCSID means now.

0
Yannick On

As you figured out, the Syntax of the CAST-function you need here is

CAST( <source_expression> AS <DataType> CCSID <expression> )

so in your code it is

CAST( MYSTRING AS BLOB CCSID 1208 )

The CCSID parameter is used only for conversions to or from one of the string data types. Use the CCSID parameter to specify the code page of the source or target string. [Source]

So with the Coded character set identifiers (CCSID) you define the code page. For example 1208 is the CCSID for UTF-8 with IBM PUA. You can see a list of IBMs CCSIDs here.

If you want to get informations on this topic in more detail you can check the IIB documentation for Version 9.0.0 or Version 10.0.0.