DB2 SQL XMLSERIALIZE / XML值的选择*

我想将DB2中SELECT SQL的所有字段输出为XML。很抱歉在这里使用“选择*”,但是在这种情况下很有意义。 已经检查了XMLSERIALIZE和XMLELEMENT命令,但是它们需要一个字段列表。 例如

SELECT XMLELEMENT (*) as X from DATA1.CUSTOMERS where CUSTOMERNO='262627'

要么

SELECT  XMLSERIALIZE (*) as X from DATA1.CUSTOMERS where CUSTOMERNO='262627'

不起作用。你能帮助我吗?

评论
  • 盛水冬
    盛水冬 回复

    There is no XML publishing function that accepts the wildcard. The easiest way would be to use XMLROW. It accepts a column list or more complex expressions and gives you some options for the final format.

    select xmlrow(col1, col2) from mytable
    

    要么

    select xmlrow(col1, col2 option row "myrowname") from mytable