Reputation: 3522
I have problem with sorting elements by varchar containing Polish characters like ą, Ą.
For example, we have following names:
Aaaa
BBcvx
Ąccc
Ddde
ądcc
Following query:
select * from something order by lower(name);
Returns result as this:
Aaaa
BBcvx
Ddde
ądcc
Ąccc
As you can see, polish characters are ignored and put at the end. It should be:
Aaaa
ądcc
Ąccc
BBcvx
Ddde
What might be the problem? Database encoding? Mine is:
SELECT * FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET';
Result:
EE8MSWIN1250
Can this be fixed without changing database encoding?
Upvotes: 3
Views: 2684
Reputation: 52863
You need to look into the NLS_SORT parameter, specifically linguistic sorting. You can use this parameter to specify what language you'd like to sort by. I suspect in your case it would be POLISH
.
Something like this
select *
from something
order by nls_lower(name, 'NLS_SORT' = 'POLISH')
NLS_LOWER()
returns a lower case character in the same manner as an ordinary LOWER()
.
You could also do this at a session level, which would change the default sort parameter for the duration of the session.
alter session set nls_sort = POLISH;
If you wanted to always use this sort; this is done the database level when the database is created.
Upvotes: 6