简体   繁体   English

Oracle SQL不适用于带连字符的单词

[英]Oracle SQL Like not working for hyphenated words

I have a table column that holds the description which looks like this: 我有一个表列,其中包含如下所示的描述:

id    description
--------------------------------------
100   ... post-doctorate ...
200   ... postdoctorate ...
300   ... post doctorate ...

I implemented a searching mechanism where users can search for keywords and somehow I'm having issues searching for these words. 我实现了一种搜索机制,用户可以搜索关键字,不知怎的,我在搜索这些单词时遇到问题。 Even though I'm using LIKE in my WHERE clause I can't seem to include all 3 rows above. 即使我在WHERE子句中使用LIKE ,我似乎也不能包含上面的所有3行。

Query 询问

WHERE description LIKE '%post-doctorate%'

I would like to be able to search all 3 of them using any of the variations illustrated as my keyword. 我希望能够使用任何作为我的关键字说明的变体搜索所有3个。

I also looked at using SOUNDEX but even that doesn't work. 我也看过使用SOUNDEX但即使这样也行不通。

Please Note 请注意

Kindly ignore the fact that I'm not using parameterized queries in here. 请忽略我在这里没有使用参数化查询的事实。 I'm aware of what it is and how to use it but this was an old project I created. 我知道它是什么以及如何使用它,但这是我创建的一个旧项目。

A method using like is: 使用like的方法是:

WHERE description LIKE '%post%doctorate%'

But that is much more general than you want. 但这比你想要的要普遍得多。 So, use regular expressions: 所以,使用正则表达式:

WHERE REGEXP_LIKE(description, 'post[- ]?doctorate'

Or, if you want to allow any character to appear at most once: 或者,如果您想允许任何字符最多出现一次:

WHERE REGEXP_LIKE(description, 'post(.)?doctorate'

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

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