我想實現是創建一個包含所有爲這個特定的XML多項目的子節點單獨行的表:構建的XMLType查詢到Oracle11g的存儲數據
<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」多個子節點,這將拋出錯誤。我如何根據父節點在單獨的行中檢索這些值。有人可以幫我糾正這個問題。任何幫助,將不勝感激。
非常感謝文森特。這工作..但我想多個「OriginalName」是在兩個不同的行,而不是顯示在一行。我可以如何修改這個來實現。 – Kiran