xQuery LIKE 运算符?
有没有办法以与 SQL 相同的方式使用 XQuery 执行 LIKE 操作?
我不想构造一些“startswith”、“endswith”和“contains”表达式。
我想要实现的示例:
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 中实现此目的?
编辑:
得到了上述问题的答案。新问题:
有没有什么办法可以反其道而行之?我想使用 sql 等效的 NOT LIKE 运算符运行这些查询。这可能吗?它必须在 FLWOR 表达式中
EDIT2:
解决了问题。您可以运行 fn:not(starts-with('123', '1')) 并返回 false。
Is there any way to perform a LIKE operation with XQuery in the same way as with SQL?
I wan't to construct some "startswith", "endswith" and "contains"-expressions.
Example of what I want to achieve:
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
Is there any way to achieve this in XQuery?
EDIT:
Got the answer to the question above. New problem:
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
EDIT2:
Solved the problem. You can run fn:not(starts-with('123', '1')) and it returns false.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XPath 2.0 和 XQuery 1.0(由 W3C 标准化)通过
matches
函数提供正则表达式支持 http://www.w3.org/TR/xpath-functions/#func-matches:当然还有像
starts-with
和contains
(均在 XPath 1.0/2.0 中)和ends-with
(仅在 XPath 2.0 中)可能就足够了。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:And of course there are functions like
starts-with
andcontains
(both in XPath 1.0/2.0), andends-with
(only in XPath 2.0) that might suffice.