我正在尝试从在 XML 类型列上创建的 Oracle 视图中获取数据。
例如:以下是 XSD:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MsrFact" type="MsrNode"/>
<xsd:complexType name="MsrNode">
<xsd:sequence>
<xsd:element name="shipTo" type="MsrValue"/>
<xsd:element name="billTo" type="MsrValue"/>
<xsd:element name="FormulaeItem" type="MsrValue" maxOccurs="10"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="MsrValue">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
插入的xml是:
<MsrFact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MsrNode>
<shipTo>
<name>shipTo</name>
</shipTo>
<billTo>
<name>billTo</name>
</billTo>
<FormulaeItem>
<name>FormulaeItem1</name>
</FormulaeItem>
<FormulaeItem>
<name>FormulaeItem2</name>
<street>100</street>
</FormulaeItem>
<FormulaeItem>
<name>FormulaeItem3</name>
</FormulaeItem>
</MsrNode>
</MsrFact>
桌子:
temptab(
ogrid number(10),
xdata xmltype);
看法:
CREATE OR REPLACE VIEW
MsrFactView(orgid,shipTo,shipToR, billTo,billToR, FormulaeItem,FormulaeItemR)
AS SELECT ogrid,
extractValue(xdata, '/MsrFact/shipTo/name'),
extractValue(xdata, '/MsrFact/shipTo/street'),
extractValue(xdata, '/MsrFact/billTo/name'),
extractValue(xdata, '/MsrFact/billTo/street'),
extractValue(xdata, '/MsrFact/FormulaeItem/name'),
extractValue(xdata, '/MsrFact/FormulaeItem/street')
FROM temptab;
我无法在此视图上编写直接选择查询,因为它给出了错误
SQL 错误:ORA-01427:单行子查询返回多于一行
01427。00000 -“单行子查询返回多于一行”
有没有办法从这个视图中获取数据?谢谢 !