我想在运行中创建一个元素,我正在尝试下面的查询,但它给了我这个错误: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" }
    }
})发布于 2012-04-27 19:08:51
试试这个:
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-28 20:15:51
DB2 XQuery似乎不支持具有动态计算名称的computed element constructors。如果可能的名称数量很少且事先已知,则可以通过列出所有可能的名称来绕过这一限制。由于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" }
    }
})https://stackoverflow.com/questions/10345467
复制相似问题