So I do have following SQL select
SELECT FOO.*, ROW_NUMBER() OVER (ORDER BY KEY ASC) AS ROW_NUMBER
FROM FOO
Key is of the type VARCHAR(12). I wonder why the hell the numbers are sorted after the letters. Every other system including UTF-8 always begins with numbers.


So a solution you can do is to take advantage of the EBCDIC character order. Special characters are sorted before the letters!
If the numeric values are replaced, for example, like 0 -> .0, the sorting automatically works correctly. As this means there is no "conversion" to ASCII involved it's also not so expensive if a lot data is sorted.
And the query for that: