Xquery 结果重复 [英] Xquery result duplicated

查看:25
本文介绍了Xquery 结果重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有得到我想要的输出.我不明白为什么结果是重复的.有人可以帮我吗?

I'm not getting the output I want. I don't understand why the result is duplicated. Can someone help me?

for $i in 1 to 2
let $rng:=random-number-generator()
let $rng1:=$rng('permute')(1 to 10)

let $rng:=$rng('next')()
let $rng2:=$rng('permute')(1 to 10)

let $rng:=$rng('next')()
let $rng3:=$rng('permute')(1 to 10)

return (string-join($rng1),string-join($rng2),string-join($rng3),",")

result:
23496815107
31018674529
31017684259

23496815107
31018674529
31017684259

推荐答案

结果重复,因为初始 for $i in 1 to 2,以及变量 $i 实际上并未在任何地方使用.

The result is duplicated because of the initial for $i in 1 to 2, and because the variable $i is not actually used anywhere.

我根据您的评论编辑了查询(得到 10 个数字).据我所知,这里的困难是链接调用(在下一个"和置换"之间交替).链式调用可以通过尾递归来完成.

I edited the query based on your comment (getting 10 numbers). From what I understand, the difficulty here is to chain the calls (alternating between 'next' and 'permute'). Chaining calls can be done with a tail recursion.

declare function local:multiple-calls(
        $rng as function(*),
        $number-of-times as xs:integer) as item()* {
  if($number-of-times le 0)
  then ()
  else
      let $rng := $rng('next')
      return ($rng('permute')(1 to 10),
              local:multiple-calls($rng, $number-of-times - 1))
};

local:multiple-calls(random-number-generator(), 10)

注意:我不确定 (1 到 10) 是否是实际需要传递给 $rng('permute') 调用的内容,或者是否试图输出十个数字.毫无疑问,我没有改变它.

Note: I am not sure if (1 to 10) is what needs to actually be passed to the call to $rng('permute'), or if it was an attempt to output ten numbers. In doubt, I haven't changed it.

这篇关于Xquery 结果重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆