xQuery LIKE 运算符?

发布于 2024-10-16 07:31:53 字数 537 浏览 5 评论 0原文

有没有办法以与 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2024-10-23 07:31:53

XPath 2.0 和 XQuery 1.0(由 W3C 标准化)通过 matches 函数提供正则表达式支持 http://www.w3.org/TR/xpath-functions/#func-matches

/user[matches(firstname, 'xxx

当然还有像 starts-withcontains (均在 XPath 1.0/2.0 中)和 ends-with (仅在 XPath 2.0 中)可能就足够了。

)]

当然还有像 starts-withcontains (均在 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:

/user[matches(firstname, 'xxx

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.

)]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文