使用plsql获取大型XML文件,从<tax x =“1”y =“2”>获取Y的重复值

时间:2015-12-10 10:20:33

标签: xml oracle plsql

我需要做以下事情:

我将XML存储在数据类型为xmldata的表中。在XML中,我对XML中的每个发票行重复了以下内容。

<InvoiceDetailItem invoiceLineNumber="1" quantity="1">

我需要从XML中的每个数量字段中获取值。

我试过了:

SELECT SUBSTR(REPLACE(REPLACE(EXTRACT(BATCH_XML,'//InvoiceDetailItem '),'<InvoiceDetailItem',''),'</InvoiceDetailItem>',''),
               INSTR(REPLACE(REPLACE(EXTRACT(BATCH_XML,'//InvoiceDetailItem '),'<InvoiceDetailItem',''),'</InvoiceDetailItem>',''),'quantity', 1, V_LCNTR)+10,
               INSTR(REPLACE(REPLACE(EXTRACT(BATCH_XML,'//InvoiceDetailItem '),'<InvoiceDetailItem',''),'</InvoiceDetailItem>',''),'UnitOfMeasure')-40) 
FROM INVOICE_INFO

其中BATCH_XML是表中xmldata类型列的名称,V_LCNTR是XML中字段出现的编号。

这适用于小发票但是当它们变大时我会收到错误:

  

ORA-19011:字符串缓冲区太小19011. 00000 - &#34;字符串缓冲区太小&#34;   原因:要求的字符串结果太大而无法返回   行动:取而代之的是结果

我看过,但所有示例似乎都只涉及简单的< tag >x< tag >,我无法找到任何可以帮助我获得价值的内容< tag x="1" y="2" >,我需要获取价值是的。

xml是

`<?xml version="1.0" encoding="utf-8"?>
<cXML xml:lang="en-GB" version="1.2.014" payloadID="elcom (inv  1).rdeint1b.2015.12.02.11.59.47.377.x.xlsx.xml" timestamp="2015-12-02T16:35:13-00:00">
<Header>
<From>
  <Credential domain="DUNS">
    <Identity>100000103885</Identity>
  </Credential>
</From>
<To>
  <Credential domain="NetworkID">
    <Identity></Identity>
  </Credential>
</To>
<Sender>
  <Credential domain="DUNS">
    <Identity></Identity>
    <SharedSecret></SharedSecret>
  </Credential>
  <UserAgent>CloudTrade</UserAgent>
</Sender>
</Header>
<Request>
<InvoiceDetailRequest>
  <InvoiceDetailRequestHeader invoiceID="RDEINT1b" purpose="standard" operation="new" invoiceDate="2015-12-01T00:00:00-00:00">
    <InvoiceDetailHeaderIndicator isVatRecoverable="yes" />
    <InvoiceDetailLineIndicator isTaxInLine="yes" />
    <InvoicePartner>
      <Contact role="issuerOfInvoice" addressID="830045568">
        <Name xml:lang="en-GB">BRAKES</Name>
        <PostalAddress>
          <DeliverTo></DeliverTo>
          <Street></Street>
          <Street></Street>
          <City></City>
          <State></State>
          <PostalCode></PostalCode>
          <Country isoCountryCode=""></Country>
        </PostalAddress>
        <Email></Email>
        <Phone name="DDI">
          <TelephoneNumber>
            <CountryCode isoCountryCode="" />
            <AreaOrCityCode />
            <Number></Number>
          </TelephoneNumber>
        </Phone>
      </Contact>
      <IdReference identifier="830045568" domain="vatID" />
      <IdReference identifier="830045568" domain="supplierTaxID" />
    </InvoicePartner>
    <InvoicePartner>
      <Contact role="soldTo" addressID="">
        <Name xml:lang="en-GB">South Lanarkshire Council</Name>
        <PostalAddress>
          <DeliverTo></DeliverTo>
          <Street>Almada Street</Street>
          <Street></Street>
          <City>Hamilton</City>
          <State></State>
          <PostalCode>ML30AL</PostalCode>
          <Country isoCountryCode="GBR">United Kingdom</Country>
        </PostalAddress>
        <Email></Email>
        <Phone name="DDI">
          <TelephoneNumber>
            <CountryCode isoCountryCode="GBR" />
            <AreaOrCityCode />
            <Number></Number>
          </TelephoneNumber>
        </Phone>
      </Contact>
      <IdReference identifier="" domain="vatID" />
      <IdReference identifier="" domain="supplierTaxID" />
    </InvoicePartner>
    <InvoicePartner>
      <Contact role="billTo" addressID="">
        <Name xml:lang="en-GB"></Name>
        <PostalAddress>
          <DeliverTo></DeliverTo>
          <Street></Street>
          <Street></Street>
          <City></City>
          <State></State>
          <PostalCode></PostalCode>
          <Country isoCountryCode=""></Country>
        </PostalAddress>
        <Email></Email>
        <Phone name="DDI">
          <TelephoneNumber>
            <CountryCode isoCountryCode="" />
            <AreaOrCityCode />
            <Number></Number>
          </TelephoneNumber>
        </Phone>
      </Contact>
      <IdReference identifier="" domain="vatID" />
      <IdReference identifier="" domain="supplierTaxID" />
    </InvoicePartner>
    <InvoicePartner>
      <Contact role="remitTo" addressID="">
        <Name xml:lang="en-GB"></Name>
        <PostalAddress>
          <DeliverTo></DeliverTo>
          <Street></Street>
          <Street></Street>
          <City></City>
          <State></State>
          <PostalCode></PostalCode>
          <Country isoCountryCode=""></Country>
        </PostalAddress>
        <Email></Email>
        <Phone name="DDI">
          <TelephoneNumber>
            <CountryCode isoCountryCode="" />
            <AreaOrCityCode />
            <Number></Number>
          </TelephoneNumber>
        </Phone>
      </Contact>
      <IdReference identifier="" domain="vatID" />
      <IdReference identifier="" domain="supplierTaxID" />
    </InvoicePartner>
    <Comments></Comments>
    <Extrinsic name="BuyersCodeForSupplier">100000103885</Extrinsic>
    <Extrinsic name="CostCentre"></Extrinsic>
    <Extrinsic name="SupplierBankAccountNumber"></Extrinsic>
    <Extrinsic name="SupplierIBAN"></Extrinsic>
    <Extrinsic name="ContractOrderReference"></Extrinsic>
    <Extrinsic name="DeliveryNoteReference"></Extrinsic>
    <Extrinsic name="SupplierPortalInvoiceID">elcom south lanarkshire (inv 1).bakes_161115_rdeint1b.2015.12.02.11.59.47.377.x.xlsx.pdf</Extrinsic>
  </InvoiceDetailRequestHeader>
  <InvoiceDetailOrder>
    <InvoiceDetailOrderInfo>
      <OrderReference orderID="3865122">
        <DocumentReference payloadID="" />
      </OrderReference>
      <SupplierOrderInfo orderID="" />
    </InvoiceDetailOrderInfo>
    <InvoiceDetailItem invoiceLineNumber="1" quantity="1">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">23.7300</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="1">
        <ItemID>
          <SupplierPartID>30846</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Brake Ciabatta Rolls</Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">23.73</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">23.73</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">23.73</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">23.73</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="2" quantity="2">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">14.7000</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="2">
        <ItemID>
          <SupplierPartID>30847</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Champion Steak  Kidney</Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">29.40</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">29.40</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">29.40</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">29.40</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="3" quantity="3">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">13.3700</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="3">
        <ItemID>
          <SupplierPartID>30850</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Champion Chicken </Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">40.11</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">40.11</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">40.11</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">40.11</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="4" quantity="1">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">23.7300</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="4">
        <ItemID>
          <SupplierPartID>30846</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Brake Ciabatta Rolls</Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">23.73</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">23.73</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">23.73</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">23.73</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="5" quantity="2">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">14.7000</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="5">
        <ItemID>
          <SupplierPartID>30847</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Champion Steak  Kidney</Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">29.40</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">29.40</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">29.40</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">29.40</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="6" quantity="3">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">13.3700</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="6">
        <ItemID>
          <SupplierPartID>30850</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Champion Chicken </Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">40.11</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">40.11</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">40.11</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">40.11</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="7" quantity="3">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">13.3700</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="7">
        <ItemID>
          <SupplierPartID>30850</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Champion Chicken </Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">40.11</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">40.11</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">40.11</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">40.11</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="8" quantity="3">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <UnitPrice>
        <Money currency="GBP">13.3700</Money>
      </UnitPrice>
      <InvoiceDetailItemReference lineNumber="8">
        <ItemID>
          <SupplierPartID>30850</SupplierPartID>
          <SupplierPartAuxiliaryID></SupplierPartAuxiliaryID>
        </ItemID>
        <Description xml:lang="en-GB">NON CORE Champion Chicken </Description>
      </InvoiceDetailItemReference>
      <SubtotalAmount>
        <Money currency="GBP">40.11</Money>
      </SubtotalAmount>
      <Tax>
        <Money currency="GBP">0.00</Money>
        <Description xml:lang="en-GB">Total Line Item Tax</Description>
        <TaxDetail purpose="tax" category="vat" percentageRate="0.00">
          <TaxableAmount>
            <Money currency="GBP">40.11</Money>
          </TaxableAmount>
          <TaxAmount>
            <Money currency="GBP">0.00</Money>
          </TaxAmount>
          <TaxLocation xml:lang="en-GB">GB</TaxLocation>
          <Description xml:lang="en-GB">Z</Description>
        </TaxDetail>
      </Tax>
      <GrossAmount>
        <Money currency="GBP">40.11</Money>
      </GrossAmount>
      <NetAmount>
        <Money currency="GBP">40.11</Money>
      </NetAmount>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
  </InvoiceDetailOrder>
  <InvoiceDetailSummary>
    <SubtotalAmount>
      <Money currency="GBP">266.70</Money>
    </SubtotalAmount>
    <Tax>
      <Money currency="GBP">0.00</Money>
      <Description xml:lang="en-GB">Total Tax</Description>
      <TaxDetail purpose="tax" category="vat" percentageRate="0">
        <TaxableAmount>
          <Money currency="GBP">266.70</Money>
        </TaxableAmount>
        <TaxAmount>
          <Money currency="GBP">0.00</Money>
        </TaxAmount>
        <TaxLocation xml:lang="en-GB">GB</TaxLocation>
        <Description xml:lang="en-GB">Z</Description>
      </TaxDetail>
    </Tax>
    <ShippingAmount>
      <Money currency="GBP">0.00</Money>
    </ShippingAmount>
    <GrossAmount>
      <Money currency="GBP">266.70</Money>
    </GrossAmount>
    <NetAmount>
      <Money currency="GBP">266.70</Money>
    </NetAmount>
    <DueAmount>
      <Money currency="GBP">266.70</Money>
        </DueAmount>
      </InvoiceDetailSummary>
    </InvoiceDetailRequest>
     </Request>
</cXML>`

1 个答案:

答案 0 :(得分:0)

我已经删除了XML以演示XMLTABLE的使用

create table invoice_info(
    batch_xml xmltype
);

insert into invoice_info values(
    xmltype('<?xml version="1.0" encoding="utf-8"?>
<cXML xml:lang="en-GB" version="1.2.014" payloadID="elcom (inv  1).rdeint1b.2015.12.02.11.59.47.377.x.xlsx.xml" timestamp="2015-12-02T16:35:13-00:00">
<Request>
<InvoiceDetailRequest>
  <InvoiceDetailOrder>
    <InvoiceDetailItem invoiceLineNumber="1" quantity="12">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="2" quantity="2">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
    <InvoiceDetailItem invoiceLineNumber="3" quantity="33">
      <UnitOfMeasure>pack</UnitOfMeasure>
      <Extrinsic name="TaxRefCode">Z</Extrinsic>
      <Extrinsic name="LinePurchaseOrderNumber"></Extrinsic>
      <Extrinsic name="QuantityOrdered"></Extrinsic>
    </InvoiceDetailItem>
  </InvoiceDetailOrder>
    </InvoiceDetailRequest>
     </Request>
</cXML>')
);

commit;

select cols.*
from invoice_info
cross join xmltable('cXML/Request/InvoiceDetailRequest/InvoiceDetailOrder/InvoiceDetailItem' passing batch_xml  /*if your column is xmltype, directly pass it. If not, convert it using xmltype(column_name)*/
    columns invoicelinenumber number path '@invoiceLineNumber',                         /*use @ to specify the attribute you want*/
    quantity number path '@quantity'
        ) cols;


INVOICELINENUMBER   QUANTITY
----------------- ----------
                1         12
                2          2
                3         33