Search code examples
sqloracle-sqldeveloperlowercase

Ordering data why does lowercase appear last


When ordering data in sql developer, why does the data with allow lowercase letters appear last?

for example

Adam, Ben, Charlotte, Matthew, emily

Why isn't it: Adam, Ben, Charlotte, emily, Matthew?

I don't necessarily want the answer to just changing it but why does it happen? Is there a setting that is ticked to make it happen or does it do it by default unless you write a statement for it not to do it?


Solution

  • Ordering in a database uses a collation. Typically, the collation is specified at the database level, but can be at the table field level and the query level.

    A collation is a ordering for the characters used by a culture in a writing system script. If the human writing system itself wouldn't define an ordering between two characters, the collation would likely fall back to a lexicographic ordering based on the character set of the collation. (Humans expect consistency even in the absence of rules that they are aware of.)

    Many systems of collations include both case sensitive and case insensitive collations as well as accent sensitive and accent insensitive collations. (So, as many as 2 x 2 collations for the same culture and character set.)

    So, somewhere your system has specified case sensitivity. You could order for your user (yourself, in this case?) by the preferred culture, case sensitivity, and accent sensitivity. But choose from collations for the same character set as the data because character set conversions can be lossy unless the source is a subset of the target.

    See PL/SQL's documentation on collations.