我正在使用 oracle 10g,下面的查询导致以下错误:
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
如果 XML 中有多个项目,我们如何提取所有元素?基本上我有兴趣将所有基础工具分开。
SELECT *
FROM xmltable(
xmlnamespaces ('http://www.cool.com/totem/1.1' AS "n1"), '/n1:totem/n1:results'
PASSING xmltype.createxml(('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<totem xmlns="http://www.cool.com/totem/1.1">
<results>
<valuationDate>2014-07-31</valuationDate>
<clientID>220</clientID>
<energy>
<underlier>
<name>CO2 CER</name>
<group>European Emissions</group>
<units>EUR / MT</units>
<pricingTime>LDN 17:00</pricingTime>
<instrument>
<period>Month</period>
<startDate>2014-12-01</startDate>
<endDate>2014-12-31</endDate>
<type>Forward</type>
<price>0.25852</price>
<priceOut>r</priceOut>
<contributors>15</contributors>
</instrument>
</underlier>
<underlier>
<name>CO2 CER SPOT</name>
<group>European Emissions</group>
<units>EUR / MT</units>
<pricingTime>LDN 17:00</pricingTime>
<instrument>
<period>Month</period>
<startDate>2014-07-31</startDate>
<endDate>2014-07-31</endDate>
<type>Spot</type>
<price>0.17</price>
<consensusPrice>0.165988</consensusPrice>
<compositePrice>0.165988</compositePrice>
<priceRange>0.01</priceRange>
<priceStddev>0.004685</priceStddev>
<contributors>10</contributors>
</instrument>
</underlier>
<underlier>
<name>CO2 EUA</name>
<group>European Emissions</group>
<units>EUR / MT</units>
<pricingTime>LDN 17:00</pricingTime>
<instrument>
<period>Month</period>
<startDate>2014-12-01</startDate>
<endDate>2014-12-31</endDate>
<type>Forward</type>
<price>6.251277</price>
<consensusPrice>6.220854</consensusPrice>
<compositePrice>6.220854</compositePrice>
<priceOut>*</priceOut>
<priceRange>0.044779</priceRange>
<priceStddev>0.014507</priceStddev>
<contributors>18</contributors>
</instrument>
<instrument>
<period>Month</period>
<startDate>2015-12-01</startDate>
<endDate>2015-12-31</endDate>
<type>Forward</type>
<price>6.399921</price>
<consensusPrice>6.382712</consensusPrice>
<compositePrice>6.382092</compositePrice>
<priceOut>s</priceOut>
<priceRange>0.05</priceRange>
<priceStddev>0.014458</priceStddev>
<contributors>18</contributors>
</instrument>
<instrument>
<period>Month</period>
<startDate>2016-12-01</startDate>
<endDate>2016-12-31</endDate>
<type>Forward</type>
<price>6.590721</price>
<consensusPrice>6.563745</consensusPrice>
<compositePrice>6.563749</compositePrice>
<priceOut>s</priceOut>
<priceRange>0.070721</priceRange>
<priceStddev>0.017205</priceStddev>
<contributors>18</contributors>
</instrument>
</underlier>
<underlier>
<name>CO2 EUA SPOT</name>
<group>European Emissions</group>
<units>EUR / MT</units>
<pricingTime>LDN 17:00</pricingTime>
<instrument>
<period>Month</period>
<startDate>2014-07-31</startDate>
<endDate>2014-07-31</endDate>
<type>Spot</type>
<price>6.19</price>
<consensusPrice>6.186412</consensusPrice>
<compositePrice>6.186412</compositePrice>
<priceRange>0.0113</priceRange>
<priceStddev>0.004984</priceStddev>
<contributors>10</contributors>
</instrument>
</underlier>
</energy>
</results>
</totem>'
))
COLUMNS valuationDate varchar2(500) PATH 'n1:valuationDate',
clientID varchar2(500) PATH 'n1:clientID',
name varchar2(500) PATH 'n1:energy/n1:underlier/n1:name',
group1 varchar2(500) PATH 'n1:energy/n1:underlier/n1:group',
units varchar2(500) PATH 'n1:energy/n1:underlier/n1:units',
pricingTime varchar2(500) PATH 'n1:energy/n1:underlier/n1:pricingTime',
period varchar2(500) PATH 'n1:energy/n1:underlier/n1:instrument/n1:period',
startDate varchar2(500) PATH 'n1:energy/n1:underlier/n1:instrument/n1:startDate',
endDate varchar2(500) PATH 'n1:energy/n1:underlier/n1:instrument/n1:endDate',
type varchar2(500) PATH 'n1:energy/n1:underlier/n1:instrument/n1:type',
price varchar2(500) PATH 'n1:energy/n1:underlier/n1:instrument/n1:price',
priceOut varchar2(500) PATH 'n1:energy/n1:underlier/n1:instrument/n1:priceOut',
contributors varchar2(500) PATH 'n1:energy/n1:underlier/n1:instrument/n1:contributors'
) AS instrument ;