0

我想动态创建一个元素,我正在尝试下面的查询,但它给了我这个错误:SQL16031N XQuery language feature using syntax "element {$first} { "Crockett" }, element last {"Johnson" } } })" is not supported

你能帮帮我吗?

    XQUERY
let $first := concat('first','')
return (element book { 
    attribute isbn {"isbn-0060229357" }, 
    element title { "Harold and the Purple Crayon"},
    element author { 
        element {$first} { "Crockett" }, 
        element last {"Johnson" }
    }
})
4

2 回答 2

0

尝试这个:

let $first := xs:QName('first')
return (element book { 
    attribute isbn {"isbn-0060229357" }, 
    element title { "Harold and the Purple Crayon"},
    element author { 
        element {$first} { "Crockett" }, 
        element last {"Johnson" }
    }
})
于 2012-04-27T11:08:51.007 回答
0

似乎 DB2 XQuery 不支持具有动态计算名称的计算元素构造函数。如果可能的名称数量很少并且事先已知,您可以通过列出所有可能性来绕过该限制。由于 DB2 似乎也不支持switch,因此我们必须使用if/else级联:

XQUERY
let $first := 'firstA'
return (element book { 
    attribute isbn {"isbn-0060229357" }, 
    element title { "Harold and the Purple Crayon"},
    element author { 
        if($first eq 'firstA')
          then element firstA { "Crockett" }
        else if($first eq 'firstB')
          then element firstB { "Crockett" }
        else if($first eq 'firstC')
          then element firstC { "Crockett" }
        else (), 
        element last {"Johnson" }
    }
})
于 2012-04-28T12:15:51.190 回答