Quote:
|
DB2 v7 ENCODING SCHEMA 0935
|
CCSID 935 is a MIXED encoding schema. With DB2 v8, your problem would be simplified since DB2 will convert the character data in your program from the encoding declared by your compiler into 935, hence you don't need to bother with the hexadecimal representation.
With a MIXED encoding scheme, you switch between 2-byte characters and 1-byte characters with the SHIFT-IN and SHIFT-OUT characters (x'0E' and x'0F'). Otherwise said, these two bytes are no characters so indeed they don't match the "_" pattern in a LIKE.
The two wildcards are "%" (x'6C') and "_" (x'6D'). To search for these characters "as is" in a LIKE, you need to escape them, e.g. by preceding them with x'E0', but then also adding
after the LIKE.
Coming back to your original question:
Quote:
The following record exists in tbl01
key_txt = x'F0F2F1F8F0F0F0F6001A021302A80E2FC3C3F0F140404040 4040'
which has substr(key_txt,9,8) = x'001A021302A80E2F'
|
This indeed starts with the 8 EBCDIC characters '02180006', then 8 other bytes, then the EBCDIC characters 'CC01 ' (ending in 6 blanks).
BUT if the data is encoded with CCSID=935, x'0E' and x'0F' have a special meaning. One of those 8 bytes is the shift-out character (x'0E'), which means that at this point double-byte interpretation begins, i.e., x'2FC3' is one character, x'C3F0' is one character, etc. There is no shift-in (x'0F') to end double-byte interpretation.
If the data has no codepage ("FOR BIT DATA"), or a single-byte codepage, x'0E' is a "normal" byte and no interpretation is done. Apparently, in your situation, this is the case. So in any "WHERE key_txt = x'......'" also the right hand side is interpreted as "FOR BIT DATA", which explains why you find your row.
Code:
select * from tbl01
where key_txt like x'F0F2F1F86D6D6D6D001A021302A80E2FC3C3F0F1404040404040'
Here, the LIKE forces *textual* interpretation, since at BIND time the characters (not bytes) "%" and "_" (i.e., in codepage 935, these are x'6C' and x'6D') must be recognised.
For a key_txt without the byte x'0E' this works: the four x'6D' are four wildchars. But with the x'0E', double-byte interpretation starts, i.e., the byte x'0E' in key_txt is compared with the double-byte x'2FC3', and these are different.
Try the following, and your row should be found:
Code:
select * from tbl01
where key_txt like x'F0F2F1F86D6D6D6D001A021302A8D62FC3C3F0F1404040404040'
i.e., replace any occurrence of x'0E' or x'0F' by the wildcard x'6D'. (Which of course is a bit too permissive, so maybe some additional rows would be returned, which you can filter out by adding the condition AND substr(key_txt, 14,1) = x'0E').
When your search string has an x'6D' or x'6E', precede it in the LIKE argument with x'E0' and add "ESCAPE x'E0'" at the end:
Code:
select * from tbl01
where key_txt like x'F0F2F1F86D6D6D6D001A021302A8D62FC3C3F0F14040404040E0D6'
ESCAPE x'E0'
would search for a "_" as the last character.
Replace x'E0' by anything else when your search pattern would already have an x'E0'.