在Oracle中工作时XML结果中断

时间:2019-03-28 10:24:15

标签: xml oracle

从oracle查询创建XML输出时,我试图中断结果。知道结果是字符串。

SELECT  XMLElement("OtherServices", 
          XMLAttributes('201903' AS "ServiceMonth", 
                         'ClientID' AS "Source",
                         'UniqueFile' as "UniqueFileID"),
            XMLForest ( 

            XMLForest (BillingDriver AS "BillingDriver", 
                      Signum   AS "Signum", 
                      Quantity  AS "Quantity",
                      Billable  AS "Billable") AS "Service"


      ))
      FROM CTE ;

输出为

<OtherServices ServiceMonth="201903" Source="ClientID" UniqueFileID="UniqueFile">
  <Service>
    <BillingDriver>Central Mgmt Service</BillingDriver>
    <Signum>SE001_RU0973</Signum>
    <Quantity>1</Quantity>
    <Billable>Yes</Billable>
  </Service>
</OtherServices> 

我需要接收的是

<OtherServices ServiceMonth="201903" Source ="ClientID" UniqueFileID ="UniqueFile">
   <Service>
      <BillingDriver>ViCS_PV</BillingDriver>
      <Signum-ID>eeditur</Signum-ID>
      <Quantity>1</Quantity>
      <Billable>Yes</Billable>
   </Service>

1 个答案:

答案 0 :(得分:0)

您可以使用the XMLSeralize function美化您的结果。作为演示,以您当前的结果作为文字:

select xmlserialize(
  document
  xmltype('<OtherServices ServiceMonth="201903" Source="ClientID" UniqueFileID="UniqueFile"><Service><BillingDriver>Central Mgmt Service</BillingDriver><Signum>SE001_RU0973</Signum><Quantity>1</Quantity><Billable>Yes</Billable></Service></OtherServices>')
  indent size=2
) as result
from dual;

RESULT                                                                               
-------------------------------------------------------------------------------------
<OtherServices ServiceMonth="201903" Source="ClientID" UniqueFileID="UniqueFile">
  <Service>
    <BillingDriver>Central Mgmt Service</BillingDriver>
    <Signum>SE001_RU0973</Signum>
    <Quantity>1</Quantity>
    <Billable>Yes</Billable>
  </Service>
</OtherServices>

因此您可以这样做:

SELECT  XMLSERIALIZE(document
          XMLElement("OtherServices", 
            XMLAttributes('201903' AS "ServiceMonth", 
                           'ClientID' AS "Source",
                           'UniqueFile' as "UniqueFileID"),
              XMLForest ( 
                XMLForest (BillingDriver AS "BillingDriver", 
                          Signum   AS "Signum", 
                          Quantity  AS "Quantity",
                          Billable  AS "Billable") AS "Service"
        ))
      indent size=2)
      FROM CTE ;