String Comparison (ORDER BY) with _ (underscore)

String Comparison (ORDER BY) with _ (underscore)

am 27.02.2006 17:47:15 von fareeda.tamboli

hi..

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
expected.

Any pointers?
Regards
Fareeda

Re: String Comparison (ORDER BY) with _ (underscore)

am 28.02.2006 04:37:44 von avidfan

fareeda.tamboli@gmail.com wrote:
> hi..
>
> 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
> expected.
>
> Any pointers?
> Regards
> Fareeda
>

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.