简体   繁体   English

Optic api 如何在列表中的位置执行操作?

[英]How can Optic api do where in list?

I have the following XQuery code that uses op:from-view .我有以下使用op:from-view XQuery 代码。 In the op:where section I am trying to select a column that can equal a list of values.op:where部分,我试图选择一个可以等于值列表的列。 When I use one value like op:eq(op:col("client"), $client1) it works fine.当我使用像op:eq(op:col("client"), $client1)这样的值时,它工作正常。 However i need it to select ($client1, $client2) .但是我需要它来选择($client1, $client2) How do I do that?我怎么做? I can't seem to find an example anywhere.我似乎无法在任何地方找到示例。 Thanks.谢谢。

Optic doesn't have an in() operator at present, so the condition would have to be passed to Optic as Optic 目前没有 in() 运算符,因此必须将条件传递给 Optic 作为

op:or((op:eq(op:col("client"), $client1), op:eq(op:col("client"), $client2)))

To make that less tedious, one possibility would be to take advantage of build-time expressions as in:为了不那么乏味,一种可能性是利用构建时表达式,如下所示:

op:or(
    let $col := op:col("client")
    for $val in ($client1, $client2)
    return op:eq($col, $val)
    )

Or to wrap that expression in a helper function:或者将该表达式包装在辅助函数中:

declare function local:in($colName as xs:string, $vals) {
    op:or(
        let $col := op:col($colName)
        for $val in ($vals)
        return op:eq($col, $val)
        )
};

and use it as follows:并按如下方式使用它:

op:where(
    local:in("client", ($client1, $client2))
    )

Hoping that helps,希望有所帮助,

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

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