【发布时间】:2021-12-02 02:58:10
【问题描述】:
我需要在字符串中搜索可能出现在其中任何位置(包括开头)的特定值。它必须是完全匹配的。
select * from LeadTimeNodes where ParentCombination like '%293 %'
所以我需要在 ParentCombination 字段中找到 293 作为它自己的实体。
字段中的一些字符串示例:
'3293 >>> 671' should not find anything as 293 is part of a bigger number 3293
'293' should find it as it is on its own
'479 >>> 12930' should not find anything as 293 is part of 12930
'6000 >>> 293' should find it
'293 >>> 1600' should find it
如果我使用上面的示例代码,它会将空格合并到搜索中并在之后的数字中工作,但是如果我在它之前放置一个空格 '% 293 %' 则它将找不到以 293 开头的字符串
希望这是有道理的。
【问题讨论】:
-
您需要为此使用正则表达式。 ¿ 你的数据库是什么?其他不太优雅的解决方案是
likes和ors的组合:ParentCombination like '293 %' OR ParentCombination like '% 293 %' OR ParentCombination like '% 293' -
什么是数据库?如果引擎支持它们,也许可以使用正则表达式来完成。
-
抱歉,我应该说,这是一个 SQL Server 数据库。