fn:compare function
The fn:compare function compares two strings.
Syntax
- string-1 and string-2
- The xs:string values that are to be compared. Db2 compares the numeric Unicode UTF-8 code value of each character.
Returned value
- -1
- If string-1 is less than string-2.
- 0
- If string-1 is equal to string-2.
- 1
- If string-1 is greater than string-2.
Two strings are compared by comparing the corresponding bytes of each string. If the strings do not have the same length, the comparison is made with a temporary copy of the shorter string that has been padded on the right with blanks so that it has the same length as the other string.
string-1 and string-2 are equal if they both have length 0 or if all corresponding bytes are equal.
If string-1 and string-2 are not equal, their relationship (that is, which has the greater value) is determined by the comparison of the first pair of unequal bytes from the left end of the strings. This comparison is made according to the collation.
If string-1 is longer than string-2, and all bytes of string-2 are equal to the leading bytes of string-1, string-1 is greater than string-2.
If string-1 or string-2 is the empty sequence, the empty sequence is returned.
Example
The following function compares 'ABC' to 'ABD' using the default collation.
fn:compare('ABC', 'ABD')
'ABC' is less than 'ABD'. The returned value is -1.