Oracle Db Sorting Issue for Turkish Text

Viewed 37

We're developing project with Spring Boot (JPA-Spring-Data) and Oracle Db. When trying to sort column which includes text, oracle gives me wrong sorting for Turkish Chars. Liquibase is our db migration tool.

This is a script for creation of table's column;

<column name="CONTENT" type="VARCHAR2(255 char)">
 <constraints nullable="false"/>
</column>

Entitys property;

@Column(name = "CONTENT", nullable = false)
private String content;

Column

When trying to order by Content; The result looks like below

enter image description here

But for example; İngilizceeee row would be after 'I' letter. There is an issue for Turkish text.

1 Answers

Oracle uses binary sort by default. This works by sorting the numerical value behind the character encoding. This works well for the English alphabet because the ASCII and EBCDIC standards define the letters A to Z in ascending numeric value. Try using 'Linquistic Sort'. See here -

https://docs.oracle.com/cd/B10501_01/server.920/a96529/ch4.htm

Example -

SELECT * FROM test ORDER BY NLSSORT(name, 'NLS_SORT=german');
Related