简体   繁体   English

Oracle:选择以字符或相关特殊字符开头的单词

[英]Oracle : select words which start by character or associated special character

I'm not very at ease with Oracle. 我对Oracle不太放心。 My project uses Java 8, Springboot, JpaRepository and an Oracle DB. 我的项目使用Java 8,Springboot,JpaRepository和Oracle DB。 I've this query in my repository : 我在我的存储库中有这个查询:

@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);

When I have the "E" letter, I well retrieve words which start with E. But it's a french project and I also need to retrieve words that start with "é" or "è". 当我收到“E”字母时,我会检索以E开头的单词。但这是一个法语项目,我还需要检索以“é”或“è”开头的单词。 And this for all letters which can be associated to special characters. 这适用于所有可以与特殊字符相关联的字母。

Does anyone have a solution ? 有没有人有办法解决吗 ?

1) Modify nls_sort, and nls_comp 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

Now your query is accent insensitive and case insensitive 现在,您的查询对重音不敏感且不区分大小写

SELECT lex FROM Lexique lex WHERE lex.titre LIKE :lettre||'%'

But changing these param will affect others queries. 但是更改这些参数会影响其他查询。

2) Use nlssort .Nlssort is returning RAW type and it's not possible to use it with like clause but you can do this workaround. 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)

But I'm not sure about the second solution 但我不确定第二种解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM