jor*_*gen 6 xml sql xpath xquery
有没有办法用XQuery以与SQL相同的方式执行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
Run Code Online (Sandbox Code Playgroud)
有没有办法在XQuery中实现这一点?
编辑:
得到了上面的问题的答案.新问题:
有没有办法以相反的方式做到这一点?我想用sql等效的NOT LIKE运算符运行这些查询.这可能吗?它必须是FLWOR表达式
EDIT2:
解决了这个问题.你可以运行fn:not(starts-with('123','1'))并返回false.
Mar*_*nen 13
XPath 2.0和XQuery 1.0(由W3C标准化)具有正则表达式支持matches功能http://www.w3.org/TR/xpath-functions/#func-matches:
/user[matches(firstname, 'xxx$')]
Run Code Online (Sandbox Code Playgroud)
当然还有像starts-with和contains(在XPath 1.0/2.0中)和ends-with(仅在XPath 2.0中)这样的功能可能就足够了.