DThompson55
DThompson55

Reputation: 111

How to convert String to BLOB in ESQL?

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).

Upvotes: 1

Views: 7235

Answers (2)

Yannick
Yannick

Reputation: 683

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.

Upvotes: 2

DThompson55
DThompson55

Reputation: 111

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

Upvotes: 1

Related Questions