How can I sort by a table column in varying cases (Oracle)

acidRain picture acidRain · Mar 20, 2012 · Viewed 22k times · Source

How can I sort a table with a column of varchar2 with characters in varying cases (UPPER and lower)?

For example, when I do an order by of the Name column, I get the following results:

ANNIE
BOB
Daniel
annie
bob

What I want is something like this:

ANNIE
annie
BOB
bob
Daniel

Answer

Michael Durrant picture Michael Durrant · Mar 20, 2012

Use lower(field), e.g.

select * from tbl order by lower(name)

If you need to address special characters for non-english languages then the other answers about NLSSORT may be what you need. If you don't I would try and KISS and use lower() as it is very easy to remember and use and be read by others (maintainability).