IBM Support

How x'FE' and x'EE' different while using in TRANSLATE Scalar Function

Question & Answer


Question

Following TRANSLATE using x'FE' works fine,
$ db2 "select translate('ABC','',X'FF49FE') from sysibm.sysdummy1"
1
---
ABC
1 record(s) selected.

But, why following fails : 
$ db2 "select translate('ABC','',X'FF49EE') from sysibm.sysdummy1"
1
---
SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815

Cause

The difference between two is invalid byte (FE) vs incomplete character (EE)


Answer

x'FE' and x'EE' both represent one byte but,

FE is invalid byte value as per Unicode rule. DB2 considers it as single byte character.
Therefore it is ok to replace x'FE' with 'A'
Our logic, here we are replacing invalid bytes to a valid value. Valid use case for translate function.

EE is valid byte value as per Unicode rule but should be part of a 3 bytes (multi-byte) character sequence.
Since the third argument is incorrect, that's why there is error (SQL0176N).
Replacing x'EE' with 'A' is wrong.
First byte EE, a valid character represent has 3 byte, If we replace EE with A , then rest of character data after EE would become invalid. It can lead to invalid Unicode characters. So, Db2 is raising error.

The difference between two are invalid byte (FE) vs incomplete character (EE)

Unicode rule regarding valid and invalid byte values (well-formed byte sequence) can be found in Table 3-7 in Unicode docs http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf

In addition document also mentions the following,
As a consequence of the well-formedness conditions specified in Table 3-7, the following byte values are disallowed in UTF-8: C0–C1, F5–FF.


Related Information

[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSAUS7","label":"DB2 Universal Database Enterprise Edition"},"ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]

Document Information

More support for:
DB2 Universal Database Enterprise Edition

Software version:
All Versions

Document number:
6953659

Modified date:
23 March 2023

UID

ibm16953659

Manage My Notification Subscriptions