DB2 Scalar functions - COLLATION_KEY
The COLLATION_KEY function returns a VARBINARY string that represents the collation key of the expression argument, in the specified collation.
The schema is SYSIBM.
The results of COLLATION_KEY for two strings can be binary compared to determine their order within the specified collation-name. For the comparison to be meaningful, the results that are used must be from the same collation-name.
If a value for length is not specified, the length of the result is determined as described in the following table:
Table 1. Determining the result length
Regardless of whether length is specified, if the length of the collation key is longer than the length of the result data type, an error is returned (SQLSTATE 42815). The actual result length of the collation key is approximately six times the length of string-expression after it is converted to UTF-16.
If string-expression is an empty string, the result is a valid collation key that can have a nonzero length.
If any argument can be null, the result can be null; if any argument is null, the result is the null value.
SELECT FIRSTNME, LASTNAME FROM EMPLOYEE ORDER BY COLLATION_KEY (LASTNAME, 'SYSTEM_923_DE')
SELECT E.WORKDEPT FROM EMPLOYEE AS E INNER JOIN SALES AS S ON COLLATION_KEY(E.LASTNAME, 'CLDR181_LFR') = COLLATION_KEY(S.SALES_PERSON, 'CLDR181_LFR') WHERE S.REGION = 'Quebec'