需要读取多个节点的值:ORA-19025: EXTRACTVALUE returns 只有一个节点的值
Need to read value of multiple node: ORA-19025: EXTRACTVALUE returns value of only one node
我可以成功读取 xml 文件:DataTransfer_HH_TWWholesale_001_004_12142020113003.xml
只有一个节点。
但是当我试图从 xml 文件中读取多个节点时:DataTransfer_HH_TWWholesale_001_009_09282020103349.xml,我得到错误ORA-19025: EXTRACTVALUE returns 只有一个节点的值。
如何从多个节点读取值?
下面是我的文件和代码:
文件:DataTransfer_HH_TWWholesale_001_004_12142020113003.xml
<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>
代码:
SELECT EXTRACTVALUE (VALUE (a1),'/Header/verb','xmlns="http://www.emeter.com/energyip/amiinterface')verb,
EXTRACTVALUE (VALUE (a1),'/Header/noun','xmlns="http://www.emeter.com/energyip/amiinterface')noun,
EXTRACTVALUE (VALUE (a1),'/Header/source','xmlns="http://www.emeter.com/energyip/amiinterface')source
FROM xml_tab,TABLE (XMLSEQUENCE (EXTRACT (xml_data,
'/MeterReadsReplyMessage/Header',
'xmlns="http://www.emeter.com/energyip/amiinterface"'
))) a1
WHERE file_name = 'DataTransfer_HH_TWWholesale_001_004_12142020113003.xml';
查询:
文件:DataTransfer_HH_TWWholesale_001_009_09282020103349.xml
<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>112448526_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SCE_640 Concentric_310037947</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2015-12-21T01:00:00.000Z</endTime>
<value>0.0</value>
<flags>0</flags>
<quality>
<validationStatus>VAL</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>
查询:
感谢阅读我的问题。
预期结果:
mRID mfg_serial_num readingTypeId measurementType Read_time
901291331_0001 SIE_640 C_310149563 LREG Register 2020-10-08T00:00:00.000Z
112448526_0001 SCE_640 Concentric_310037947 LREG Register 2015-12-21T01:00:00.000Z
EXTRACT
and EXTRACTVALUE
XML 函数已弃用。使用 XMLTABLE
代替:
SELECT t.file_name,
x.*
FROM xml_tab t
CROSS APPLY XMLTABLE(
XMLNAMESPACES( DEFAULT 'http://www.emeter.com/energyip/amiinterface' ),
'/MeterReadsReplyMessage/payload/MeterReading'
PASSING t.xml_data
COLUMNS
mRID VARCHAR2(20) PATH './ServiceDeliveryPoint/mRID',
mfg_serial_num VARCHAR2(20) PATH './Meter/mRID',
readingTypeID VARCHAR2(10) PATH './IntervalBlock/readingTypeId',
measurement_type VARCHAR2(10) PATH './IntervalBlock/ReadingType/measurementType',
reading_time TIMESTAMP WITH TIME ZONE PATH '//IReading/endTime'
) x;
其中,对于您的示例数据:
CREATE TABLE xml_tab ( file_name, xml_data ) AS
SELECT 'DataTransfer_HH_TWWholesale_001_004_12142020113003.xml',
XMLTYPE(
'<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>'
) FROM DUAL UNION ALL
SELECT 'DataTransfer_HH_TWWholesale_001_009_00000000000000.xml',
XMLType( '<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>112448526_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SCE_640 Concentric_310037947</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2015-12-21T01:00:00.000Z</endTime>
<value>0.0</value>
<flags>0</flags>
<quality>
<validationStatus>VAL</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>'
) FROM DUAL;
输出:
FILE_NAME | MRID | MFG_SERIAL_NUM | READINGTYPEID | MEASUREMENT_TYPE | READING_TIME
:----------------------------------------------------- | :------------- | :------------------- | :------------ | :--------------- | :----------------------------------
DataTransfer_HH_TWWholesale_001_004_12142020113003.xml | 901291331_0001 | SIE_640 C_310149563 | LREG | Register | 2020-10-08T00:00:00.000000000+00:00
DataTransfer_HH_TWWholesale_001_009_00000000000000.xml | 901291331_0001 | SIE_640 C_310149563 | LREG | Register | 2020-10-08T00:00:00.000000000+00:00
DataTransfer_HH_TWWholesale_001_009_00000000000000.xml | 112448526_0001 | SCE_640 Concentric_3 | LREG | Register | 2015-12-21T01:00:00.000000000+00:00
db<>fiddle here
我可以成功读取 xml 文件:DataTransfer_HH_TWWholesale_001_004_12142020113003.xml 只有一个节点。
但是当我试图从 xml 文件中读取多个节点时:DataTransfer_HH_TWWholesale_001_009_09282020103349.xml,我得到错误ORA-19025: EXTRACTVALUE returns 只有一个节点的值。
如何从多个节点读取值?
下面是我的文件和代码:
文件:DataTransfer_HH_TWWholesale_001_004_12142020113003.xml
<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>
代码:
SELECT EXTRACTVALUE (VALUE (a1),'/Header/verb','xmlns="http://www.emeter.com/energyip/amiinterface')verb,
EXTRACTVALUE (VALUE (a1),'/Header/noun','xmlns="http://www.emeter.com/energyip/amiinterface')noun,
EXTRACTVALUE (VALUE (a1),'/Header/source','xmlns="http://www.emeter.com/energyip/amiinterface')source
FROM xml_tab,TABLE (XMLSEQUENCE (EXTRACT (xml_data,
'/MeterReadsReplyMessage/Header',
'xmlns="http://www.emeter.com/energyip/amiinterface"'
))) a1
WHERE file_name = 'DataTransfer_HH_TWWholesale_001_004_12142020113003.xml';
查询:
<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>112448526_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SCE_640 Concentric_310037947</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2015-12-21T01:00:00.000Z</endTime>
<value>0.0</value>
<flags>0</flags>
<quality>
<validationStatus>VAL</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>
查询:
感谢阅读我的问题。
预期结果:
mRID mfg_serial_num readingTypeId measurementType Read_time
901291331_0001 SIE_640 C_310149563 LREG Register 2020-10-08T00:00:00.000Z
112448526_0001 SCE_640 Concentric_310037947 LREG Register 2015-12-21T01:00:00.000Z
EXTRACT
and EXTRACTVALUE
XML 函数已弃用。使用 XMLTABLE
代替:
SELECT t.file_name,
x.*
FROM xml_tab t
CROSS APPLY XMLTABLE(
XMLNAMESPACES( DEFAULT 'http://www.emeter.com/energyip/amiinterface' ),
'/MeterReadsReplyMessage/payload/MeterReading'
PASSING t.xml_data
COLUMNS
mRID VARCHAR2(20) PATH './ServiceDeliveryPoint/mRID',
mfg_serial_num VARCHAR2(20) PATH './Meter/mRID',
readingTypeID VARCHAR2(10) PATH './IntervalBlock/readingTypeId',
measurement_type VARCHAR2(10) PATH './IntervalBlock/ReadingType/measurementType',
reading_time TIMESTAMP WITH TIME ZONE PATH '//IReading/endTime'
) x;
其中,对于您的示例数据:
CREATE TABLE xml_tab ( file_name, xml_data ) AS
SELECT 'DataTransfer_HH_TWWholesale_001_004_12142020113003.xml',
XMLTYPE(
'<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>'
) FROM DUAL UNION ALL
SELECT 'DataTransfer_HH_TWWholesale_001_009_00000000000000.xml',
XMLType( '<MeterReadsReplyMessage xmlns="http://www.emeter.com/energyip/amiinterface">
<Header>
<verb>create</verb>
<noun>DTSMeterReads</noun>
<revision>2</revision>
<source>EIP</source>
</Header>
<payload>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>901291331_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SIE_640 C_310149563</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2020-10-08T00:00:00.000Z</endTime>
<value>0.0</value>
<quality>
<validationStatus>EST</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
<MeterReading>
<ServiceDeliveryPoint>
<mRID>112448526_0001</mRID>
<idType>SDP_X_UDC_ASSET_ID</idType>
</ServiceDeliveryPoint>
<Meter>
<mRID>SCE_640 Concentric_310037947</mRID>
<idType>METER_X_UDC_ASSET_ID</idType>
</Meter>
<IntervalBlock>
<readingTypeId>LREG</readingTypeId>
<ReadingType>
<measurementType>Register</measurementType>
<touBinNumber>0</touBinNumber>
<unit>L</unit>
<channelNumber>1</channelNumber>
<direction>Delivered</direction>
</ReadingType>
<IReading>
<endTime>2015-12-21T01:00:00.000Z</endTime>
<value>0.0</value>
<flags>0</flags>
<quality>
<validationStatus>VAL</validationStatus>
<locked>false</locked>
</quality>
</IReading>
</IntervalBlock>
</MeterReading>
</payload>
</MeterReadsReplyMessage>'
) FROM DUAL;
输出:
FILE_NAME | MRID | MFG_SERIAL_NUM | READINGTYPEID | MEASUREMENT_TYPE | READING_TIME :----------------------------------------------------- | :------------- | :------------------- | :------------ | :--------------- | :---------------------------------- DataTransfer_HH_TWWholesale_001_004_12142020113003.xml | 901291331_0001 | SIE_640 C_310149563 | LREG | Register | 2020-10-08T00:00:00.000000000+00:00 DataTransfer_HH_TWWholesale_001_009_00000000000000.xml | 901291331_0001 | SIE_640 C_310149563 | LREG | Register | 2020-10-08T00:00:00.000000000+00:00 DataTransfer_HH_TWWholesale_001_009_00000000000000.xml | 112448526_0001 | SCE_640 Concentric_3 | LREG | Register | 2015-12-21T01:00:00.000000000+00:00
db<>fiddle here