【问题标题】:XQuery Type of value does not matchXQuery 值类型不匹配
【发布时间】:2017-03-15 18:43:34
【问题描述】:
declare variable $fb := doc("factbook.xml")/mondial;
for $c in $fb//country
where ($c/encompassed/@continent = 'f0_119') and ($c/@population < 100000)
return concat('Country: ',$c/name, ', Population: ',$c/@population);

它返回:

  Type Error: Type of value '

()
' does not match sequence type: xs:anyAtomicType?
At characters 11681-11698
At File "q2_3.xq", line 4, characters 13-67
At File "q2_3.xq", line 4, characters 13-67
At File "q2_3.xq", line 4, characters 13-67

但是,如果我不执行 concat 返回,只需命名或填充它就会起作用,最奇怪的是我还有另一个程序:

declare variable $fb := doc("factbook.xml")/mondial;
for $c in $fb//country
where $c/religions = 'Seventh-Day Adventist'
order by $c/name
return concat('Country: ',$c/name, ', Population: ',$c/@population);

返回语法完全相同,但是,它可以工作。 为什么会这样?

【问题讨论】:

    标签: xquery


    【解决方案1】:

    如果没有看到您的数据示例,则无法确定,但如果$c/name 返回多个值,那么您的错误将是有意义的。有多个name 元素的结果吗?

    【讨论】:

    • 你是对的,有 country/name ,但是也有 country/city/name ,那我应该如何修改让它只显示 country/name
    • @NeoZhang country/city/name 不会有问题。尝试将您的退货声明更改为($c/name)[1]
    • @NeoZhang 如果这回答了您的问题,请单击此答案左侧的复选图标将其标记为已接受。
    猜你喜欢
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 2014-11-10
    • 2013-12-22
    相关资源
    最近更新 更多