xQuery LIKE 运算符? [英] xQuery LIKE-operator?
问题描述
有没有办法像使用 SQL 一样使用 XQuery 执行 LIKE 操作?
Is there any way to perform a LIKE operation with XQuery in the same way as with SQL?
我不想构建一些startswith"、endswith"和contains"表达式.
I wan't to construct some "startswith", "endswith" and "contains"-expressions.
我想要实现的示例:
for $x in /user where $x/firstname LIKE '%xxx' return $x
for $x in /user where $x/middlename LIKE 'xxx%' return $x
for $x in /user where $x/lastname LIKE '%xxx%' return $x
有没有办法在 XQuery 中实现这一点?
Is there any way to achieve this in XQuery?
得到了上面问题的答案.新问题:
Got the answer to the question above. New problem:
有什么办法可以反过来做吗?我想使用 SQL 等效 NOT LIKE 运算符运行这些查询.这可能吗?它必须在 FLWOR 表达式中
Would there be any way to do this the opposite way around? I would like to run those queries with the sql equivalent NOT LIKE operator. Is this possible? It has to be in an FLWOR-expression
编辑 2:
解决了问题.您可以运行 fn:not(starts-with('123', '1')) 并返回 false.
Solved the problem. You can run fn:not(starts-with('123', '1')) and it returns false.
推荐答案
XPath 2.0 和 XQuery 1.0(由 W3C 标准化)通过 matches
函数支持正则表达式http://www.w3.org/TR/xpath-functions/#func-matches:
XPath 2.0 and XQuery 1.0 (as standardized by the W3C) have regular expression support with the matches
function http://www.w3.org/TR/xpath-functions/#func-matches:
/user[matches(firstname, 'xxx$')]
当然还有像 starts-with
和 contains
(都在 XPath 1.0/2.0 中)和 ends-with
(仅在 XPath 2.0 中)可能就足够了.
And of course there are functions like starts-with
and contains
(both in XPath 1.0/2.0), and ends-with
(only in XPath 2.0) that might suffice.
这篇关于xQuery LIKE 运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!