sql - XMLELEMENT 属性组
问题描述
我们能够生成如下所示的 XML 结构,其中数据是线性的,没有关于模型的分组。
<transaction>
<header>
<trantype>siv</trantype>
<options>ModelMasterEdit</options>
</header>
<detail>
<record>
<Description>test_060420</Description>
<Details>Test Details</Details>
<Canonical>A1863</Canonical>
<Classification>PH</Classification>
<Tree>XM</Tree>
<Manufacturer>Apple</Manufacturer>
<Forecast>Apple Smart Phones</Forecast>
<Category>Cellular Phones</Category>
<SerialCaption>Serial Number</SerialCaption>
<Description>test_060421</Description>
<Details>Test Details</Details>
<Canonical>A1863</Canonical>
<Classification>PH</Classification>
<Tree>XM</Tree>
<Manufacturer>Apple</Manufacturer>
<Forecast>Apple Smart Phones</Forecast>
<Category>Cellular Phones</Category>
<SerialCaption>Serial Number</SerialCaption>
</record>
</detail>
</transaction>
但是,我们需要通过根据型号对模型属性进行分组来以以下格式输出
<transaction>
<header>
<trantype>siv</trantype>
<options>ModelMasterEdit</options>
</header>
<detail>
<record>
<Description>test_060420</Description>
<Details>Test Details</Details>
<Canonical>A1863</Canonical>
<Classification>PH</Classification>
<Tree>XM</Tree>
<Manufacturer>Apple</Manufacturer>
<Forecast>Apple Smart Phones</Forecast>
<Category>Cellular Phones</Category>
<SerialCaption>Serial Number</SerialCaption>
</record>
<record>
<Description>test_060421</Description>
<Details>Test Details</Details>
<Canonical>A1863</Canonical>
<Classification>PH</Classification>
<Tree>XM</Tree>
<Manufacturer>Apple</Manufacturer>
<Forecast>Apple Smart Phones</Forecast>
<Category>Cellular Phones</Category>
<SerialCaption>Serial Number</SerialCaption>
</record>
</detail>
</transaction>
我们在下面创建 SQL 查询以生成第一个 XML,但无法生成所需的第二个 xml
SELECT XMLELEMENT ("transaction",XMLELEMENT("header", XMLELEMENT ("trantype", 'siv'), XMLELEMENT ("options", 'ModelMasterEdit')),
XMLELEMENT ( "detail",
XMLELEMENT (
"record",
XMLAGG (
XMLELEMENT (evalname(attribute_name), attribute_value)))))
FROM XXCMST_INV_CMT_PRODUCT_TBL i
WHERE soa_instance_id = 64202001
AND source_system = 'EIS'
表数据:
解决方案
推荐阅读
- javascript - 如何在字符串中使用 JavaScript 变量
- apache-spark - setLocalProperty 对 SqlContext[Spark3] 有效吗?
- matlab - Matlab:如何在忽略时间(HMS)的情况下比较日期(YMD)?
- javascript - 在书签()函数中发送消息时未定义消息
- c - 使用缓冲区而不是直接对整数使用 scanf 函数的原因
- mongodb - Spring Data Mongo DB String to Sum 聚合
- regex - Powershell 正则表达式函数删除 CRLF
- python - python 命令只给出“Python”
- jquery - 可拖动的黑色圆圈图标不应拖动到灰色圆圈之外(使用 jquery ui 可拖动)
- ruby-on-rails - 在带有 Postgresql 的 Rails 中使用迁移创建存储过程