简体   繁体   English

ms-access数据库中带有正则表达式的SQL查询

[英]SQL query with regex in ms-access database

I'm working with C# .Net and ms-access database. 我正在使用C#.Net和ms-access数据库。

I have the following SQL query: 我有以下SQL查询:

  `Select ... Like "%<aaa>%"+prmPhrase+"%</aaa>%"` 

The query is looking for a phrase inside a database field which contains xml data. 该查询正在包含XML数据的数据库字段内寻找短语。

the query works very quickly, but it returns a lot of false results. 该查询工作非常迅速,但是返回了许多错误的结果。 I can't search only the exact phrase because i have a list of word boundry markers: 我不能只搜索确切的短语,因为我有一个单词边界标记列表:

  ' ', '-', '.', ':', ',', ';', '/'

for example: 例如:

  prmPhrase = run  
  "i run home" -ok  
  "i.run-home" - ok  
  "running" - false result - not ok  

It takes me a lot of time to extract the ok results by code, and return only the ok sentences. 通过代码提取确定的结果并仅返回确定的语句需要花费大量时间。

I would like to know if there is anything like regex or something which i could do a better query to return only the ok results without the false ones. 我想知道是否存在像正则表达式之类的东西,或者我可以做更好的查询以仅返回确定的结果而没有错误的结果。

maybe this could help: 也许这可以帮助:

Search for "whole word match" in MySQL 在MySQL中搜索“全字匹配”

Thanks For Advance! 感谢前进!

Your task could be solved with something like "%" + SetA + "run" + SetB + "%" 您的任务可以通过诸如“%” + SetA +“ run” + SetB +“%”之类的东西来解决
where setA all symbols allowed before phrase (eg [az]*, to prevent end of tag, so % does not work), setB - all allowed delimiters (eg [^a-z0-9]). setA-所有允许在短语之前使用的符号(例如[az] *,以防止标签结尾,因此%无效),setB-所有允许的定界符(例如[^ a-z0-9])。
I am afraid you could not define SetA with %, _, [] So you should simplify your task. 恐怕您无法使用%,_,[]定义SetA,因此应简化您的任务。

This doesn't help much in SQL, but Access can use the File System Object's RegExp support. 这在SQL中没有多大帮助,但是Access可以使用文件系统对象的RegExp支持。 Given the way your data is stored, that's likely not going to be much of a slowdown, since your LIKE matches wouldn't be using any indexes well anyway. 考虑到数据的存储方式,这不会造成太大的影响,因为您的LIKE匹配无论如何都不会很好地使用任何索引。

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

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