我想要实现的是为这个特定的 xml 创建一个包含所有多项目子节点的单独行的表:
<ABCD>
<EMPLOYEE id="11" date="25-Apr-1983">
<NameDetails>
<Name NameType="a">
<NameValue>
<FirstName>ABCD</FirstName>
<Surname>PQR</Surname>
<OriginalName>TEST1</OriginalName>
<OriginalName>TEST2</OriginalName>
</NameValue>
</Name>
<Name NameType="b">
<NameValue>
<FirstName>TEST3</FirstName>
<Surname>TEST3</Surname>
</NameValue>
<NameValue>
<FirstName>TEST5</FirstName>
<MiddleName>TEST6</MiddleName>
<Surname>TEST7</Surname>
<OriginalName>JAB1</OriginalName>
</NameValue>
<NameValue>
<FirstName>HER</FirstName>
<MiddleName>HIS</MiddleName>
<Surname>LOO</Surname>
</NameValue>
</Name> <Name NameType="c">
<NameValue>
<FirstName>CDS</FirstName>
<MiddleName>DRE</MiddleName>
<Surname>QWE</Surname>
</NameValue>
<NameValue>
<FirstName>CCD</FirstName>
<MiddleName>YTD</MiddleName>
<Surname>QQA</Surname>
</NameValue>
<NameValue>
<FirstName>DS</FirstName>
<Surname>AzDFz</Surname>
</NameValue>
</Name>
</NameDetails>
</EMPLOYEE >
</ABCD>
我尝试使用查询:
SELECT t.personid,n.nametypeid,t.firstname,t.middlename,t.surname,t.maidenname,t.originalName
FROM xml_files p,master_nametypes n,
XMLTable(
'for $i in ADCD/Employee/NameDetails/Name/NameValue
return <row>
{
$i/../../../@id,
$i/../@NameType,
$i/FirstName,
$i/MiddleName,
$i/OriginalName
$i/Surname,
$i/MaidenName,
$i/Suffix,
$i/SingleStringName,
$i/EntityName
}
</row>'
PASSING p.filecontent
COLUMNS
personid number PATH '@id',
nametypeid VARCHAR2(255) PATH '@NameType',
firstname VARCHAR2(4000) PATH 'FirstName',
middlename VARCHAR2(4000) PATH 'MiddleName',
surname VARCHAR2(4000) PATH 'Surname',
maidenname VARCHAR2(4000) PATH 'MaidenName',
originalName VARCHAR2(4000) PATH '.'
) t where t.nametypeid = n.nametype and n.recordtype = 'Employee'
;
但是当“NAMEVALUE”节点下有多个像“ORIGINALNAME”这样的子节点时,这将引发错误。如何根据父节点在单独的行中检索这些值。有人可以帮我纠正这个查询。任何帮助,将不胜感激。