Search code examples
sqloracle-databaseselectsql-order-bycase-sensitive

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


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

Solution

  • 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).