String Comparison (ORDER BY) with _ (underscore)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I need to select records ordered by a string column. But when I order
by with data containing an underscore, the result is not as expected.

Following probably will make the problem clearer:

When I try this on Oracle:
SELECT LEAST('aa','ab','a_') FROM DUAL;
The results is 'a_'

but when I try this on MySQL
SELECT LEAST('aa','ab','a_');
The results is 'aa'

whereas I would actually need/expect "a_".
For all other _ characters (like "-". "%") it works fine just as

Any pointers?

Re: String Comparison (ORDER BY) with _ (underscore) wrote:
Quoted text here. Click to load it

Not sure where to find it, but it looks like the 2 db engines are using
different COLLATING SEQUENCES.  Make sure the 2 databases are at the
very least using the same character sets.

Site Timeline