我对 Oracle 不是很放心。我的项目使用 Java 8、Springboot、JpaRepository 和 Oracle DB。我的存储库中有这个查询:
@Query("SELECT lex FROM Lexique lex WHERE UPPER(lex.titre) LIKE UPPER(CONCAT(:lettre,'%')) order by lex.titre ASC ")
List<Lexique> findAllWordsStartingBy(@Param("lettre") String lettre);
当我有“E”字母时,我很好地检索以 E 开头的单词。但这是一个法语项目,我还需要检索以“é”或“è”开头的单词。 这适用于所有可以与特殊字符相关联的字母。
有没有人有解决办法?
最佳答案
1) 修改nls_sort和nls_comp
alter session set nls_sort=french_m_ai; --(_m -> multilingual , _ai -> accent insensitive and case insensitive )
alter session set nls_comp=linguistic; -- comparisions base on linguistic rule
现在您的查询不区分重音和大小写
SELECT lex FROM Lexique lex WHERE lex.titre LIKE :lettre||'%'
但是更改这些参数会影响其他查询。
2) 使用 nlssort
。Nlssort 返回 RAW 类型,不能将它与 like 子句一起使用,但您可以执行此解决方法。
@Query("SELECT lex FROM Lexique lex WHERE nlssort(substr(lex.titre,1,1), 'NLS_SORT=FRENCH_M_AI') = nlssort(:letter, 'NLS_SORT=FRENCH_M_AI') ", nativeQuery = true)
但是我不确定第二种方案
关于java - 甲骨文 : select words which start by character or associated special character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55827476/