在 RPGLE 中使用 XML 函数(XMLAGG)
Using XML Functions(XMLAGG) in RPGLE
我有一个 table(TableA),我从它的两个字段(Fld1 和 Fld2)创建一个 XML
select
XMLSERIALIZE(
XMLAGG(
XmlElement(Name "Tag",
XmlElement(Name "PARTNUMBER", RTrim(Fld1)),
XmlElement(Name "PART_DESCRIPTION", RTrim(Fld2)))
)
AS varchar(2000) )
From TableA
输出如下:
<Tag><PARTNUMBER>401791</PARTNUMBER><PART_DESCRIPTION>ECM-NO START,ME17</PART_DESCRIPTION></Tag><Tag><PARTNUMBER>401792</PARTNUMBER><PART_DESCRIPTION>CALIBRATION-111,IND,18,NA</PART_DESCRIPTION></Tag>
现在我的要求是应该只来一次。它应该绑定整个 XML 而不是每一行。
所需的输出应如下所示:
<Tag><PARTNUMBER>401791</PARTNUMBER><PART_DESCRIPTION>ECM-NO> START,ME17</PART_DESCRIPTION><PARTNUMBER>401792</PARTNUMBER><PART_DESCRIPTION>CALIBRATION-111,IND,18,NA</PART_DESCRIPTION></Tag>
请帮忙!
对于您请求的输出,这应该可以解决问题...
SELECT
XMLELEMENT(NAME "TAG",
XMLAGG(
XMLFOREST(RTRIM(Fld1) AS "PARTNUMBER",
RTRIM(Fld2) AS "PART_DESCRIPTION"
)
)
)
AS XML_EXAMPLE
FROM TableA
现在,在生成它之后,您可以将其放入另一个 select 语句中,并使用 XMLSERIALIZE 在开头添加您需要的任何内容。
此外,这里是关于上面使用的三个 XML 函数的 IBM 文档。
XML元素:https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzscaxmlelem.htm
XMLAGG:https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzcolxmlagg.htm
XML森林:https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzscaxmlforest.htm
我有一个 table(TableA),我从它的两个字段(Fld1 和 Fld2)创建一个 XML
select
XMLSERIALIZE(
XMLAGG(
XmlElement(Name "Tag",
XmlElement(Name "PARTNUMBER", RTrim(Fld1)),
XmlElement(Name "PART_DESCRIPTION", RTrim(Fld2)))
)
AS varchar(2000) )
From TableA
输出如下:
<Tag><PARTNUMBER>401791</PARTNUMBER><PART_DESCRIPTION>ECM-NO START,ME17</PART_DESCRIPTION></Tag><Tag><PARTNUMBER>401792</PARTNUMBER><PART_DESCRIPTION>CALIBRATION-111,IND,18,NA</PART_DESCRIPTION></Tag>
现在我的要求是应该只来一次。它应该绑定整个 XML 而不是每一行。
所需的输出应如下所示:
<Tag><PARTNUMBER>401791</PARTNUMBER><PART_DESCRIPTION>ECM-NO> START,ME17</PART_DESCRIPTION><PARTNUMBER>401792</PARTNUMBER><PART_DESCRIPTION>CALIBRATION-111,IND,18,NA</PART_DESCRIPTION></Tag>
请帮忙!
对于您请求的输出,这应该可以解决问题...
SELECT
XMLELEMENT(NAME "TAG",
XMLAGG(
XMLFOREST(RTRIM(Fld1) AS "PARTNUMBER",
RTRIM(Fld2) AS "PART_DESCRIPTION"
)
)
)
AS XML_EXAMPLE
FROM TableA
现在,在生成它之后,您可以将其放入另一个 select 语句中,并使用 XMLSERIALIZE 在开头添加您需要的任何内容。
此外,这里是关于上面使用的三个 XML 函数的 IBM 文档。
XML元素:https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzscaxmlelem.htm
XMLAGG:https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzcolxmlagg.htm
XML森林:https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/db2/rbafzscaxmlforest.htm