我们必须使用pl/sql读取xml。下面粘贴了xml的前几行。在xml中,对于一个节点,有一个设备。对于一台设备,有多个机柜。对于一个机柜,有多个Subrack &对于一个Subrack,有多个主板。
我们开发了一个下面的查询来解析。
第1步:
create table emp_xml of xmltype xmltype store as securefile binary xml;第2步:
insert into emp_xml values (xmltype(bfilename('XML_DIR','ahm_2015_04_01_172428.xml'), nls_charset_id('AL32UTF8') ));第3步:
select * from emp_xml;第4步:
select x.*
from emp_xml t,
xmltable(xmlnamespaces(default 'http://www.ericsson.com/axe/export/hw'(http :/ /
www.ericsson.com / axe /
export /
hw%27)),
'/NetworkInventory/Node' passing t.object_value columns
SiteName varchar2(10) path '@Name',
SiteType varchar2(10) path '@Type',
BuildingPractice varchar2(10) path
'//Equipment/@BuildingPractice') x;此查询正在运行perfectly.But当我尝试获取机柜或子机架详细信息时,我们得到以下错误。
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
ORA-06512: at line 33
19279. 00000 - "XQuery dynamic type mismatch: expected singleton sequence - got multi- item sequence"
*Cause: The XQuery sequence passed in had more than one item.
*Action: Correct the XQuery expression to return a single item sequence.下面给出了XML的前几行。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<NetworkInventory xmlns="http://www.ericsson.com/axe/export/hw" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ericsson.com/axe/export/hw file:/opt/ericsson/nms_smo_srv/etc/export.xsd">
<Description>AXE HARDWARE INVENTORY DATA</Description>
<ExportDateTime Date="2015-04-01" Time="17:24:28"/>
<Node AdjustDate="2015-03-21" FunctionType=" " Name="BSC20" Site=" " Type="AXE" UserLabel="">
<Equipment BuildingPractice="BYB501">
<Cabinet Position="CabNumber=1">
<Subrack Name="FAN-1" Position="X=3,Y=2" Type="CP">
<Board Name=" " SlotPosition="255" Type="CP">
<ProductData FirstOperationDate="2013-11-20" LastChangedDate="2013-11-20" ManufacturedDate=" " ProductName=" " ProductNumber=" " ProductRevision=" " SerialNumber=" " Supplier="Ericsson AB"/>
</Board>
<Board Name=" " SlotPosition="255" Type="CP">
<ProductData FirstOperationDate="2013-11-20" LastChangedDate="2013-11-20" ManufacturedDate=" " ProductName=" " ProductNumber=" " ProductRevision=" " SerialNumber=" " Supplier="Ericsson AB"/>
</Board>
</Subrack>发布于 2015-04-20 21:56:05
因为您的文件柜没有设置为单次迭代。
当您希望以关系格式表示重复组时,必须提取主XQuery表达式中的项序列。
然后将每一项传递给columns子句,以进一步分解为列。
发布于 2015-04-20 23:12:35
您正在尝试扩展一种类似于嵌套表的结构。设备节点可以有多个橱柜,因此要从这些橱柜中提取详细信息,需要将它们传递给第二个XMLTable:
select x.SiteName, x.SiteType, x.BuildingPractice, y.Position
from emp_xml t
cross join xmltable(
xmlnamespaces(default 'http://www.ericsson.com/axe/export/hw'),
'/NetworkInventory/Node' passing t.object_value columns
SiteName varchar2(10) path '@Name',
SiteType varchar2(10) path '@Type',
BuildingPractice varchar2(10) path 'Equipment/@BuildingPractice',
Equipment XMLType path 'Equipment'
) x
cross join xmltable(
xmlnamespaces(default 'http://www.ericsson.com/axe/export/hw'),
'//Cabinet' passing x.Equipment columns
Position varchar2(15) path '@Position'
) y;
SITENAME SITETYPE BUILDINGPRACTICE POSITION
---------- ---------- ---------------- ---------------
BSC20 AXE BYB501 CabNumber=1 要获得SubRack数据,您需要将其传递到第三级XMLTable,等等。
https://stackoverflow.com/questions/29747754
复制相似问题