【问题标题】:How to convert xml stored as clob to temporary table in DB2如何将存储为 clob 的 xml 转换为 DB2 中的临时表
【发布时间】:2016-10-04 06:10:19
【问题描述】:

xml 以 CLOB 格式存储在 DB2 的表中

我想在存储过程中将此 xml 转换为表格格式

例如。 xml是这样的

 <Orders>
     <order id="1" name="order1" dateOfIssue="2015-01-09"/>
     <order id="2" name="order2" dateOfIssue="2009-01-08"/>
</Orders>

它应该像这样插入到表中

id  | Name   | DateOFIssue
1   | order1 | 2015-01-09
2   | order2 | 2009-01-08

【问题讨论】:

  • 很遗憾,您没有提及您的 DB2 版本和平台;如果您的 DB2 实例支持 XMLPARSE()XMLTABLE(),请考虑使用它们。

标签: xml stored-procedures db2 clob


【解决方案1】:

我的建议是使用 DB2 PureXML 特性,其中 XML 数据可以以分层形式直接存储到表中。并且可以通过 XQuery 和 SQL 检索它,您可以将其作为存储过程。

【讨论】:

    【解决方案2】:

    您可以使用问题中描述的存储过程,但最短路径是使用XMLTABLE 编写查询。这看起来像这里(未经测试):

    select x.*
    from yourTableWithCLOB, XMLTABLE('$CLOBCOLUMNNAME/Orders/order' columns
    id int path '@id',
    name varchar(20) path '@name',
    DateOfIssue date path '@dateOfIssue'
    ) as x
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-30
      • 2018-08-05
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多