我正在使用 Oracle 11g XMLTABLE 函数从附加的 XML 文件中获取数据。当我执行代码时,我得到 3 行。我正在检索产品,为与客户对应的每个产品正确生成一行。问题是我没有得到其余的客户数据,我得到了 CustomerName、CustomerDOB 和 CustomerEmail 的空值。出于某种原因,我正在使用的代码,Oracle 没有获取 2 个级别。请帮忙!我究竟做错了什么?
XML
<?xml version="1.0" encoding="iso-8859-1"?>
<USACustomers>
<NewYorkCustomers>
<Customer>
<CustomerData>
<CustomerName>John Stark</CustomerName>
<CustomerDOB>07/09/1973</CustomerDOB>
<CustomerEmail>j.stark@liquid.com</CustomerEmail>
</CustomerData>
<CustomerAddress>
<Address>400 Railroad Way</Address>
<City>Larchmont</City>
<State>NY</State>
<Zip>10542</Zip>
</CustomerAddress>
<CustomerProducts>
<CustomerProduct>
<PoductType>CTD</PoductType>
<ProductNumber>2050035302</ProductNumber>
</CustomerProduct>
<CustomerProduct>
<PoductType>REC</PoductType>
<ProductNumber>2050920400</ProductNumber>
</CustomerProduct>
</CustomerProducts>
</Customer>
<Customer>
<CustomerData>
<CustomerName>Maria Stark</CustomerName>
<CustomerDOB>07/09/1972</CustomerDOB>
<CustomerEmail>m.stark@liquid.com</CustomerEmail>
</CustomerData>
<CustomerAddress>
<Address>410 Railroad Way</Address>
<City>Larchmont</City>
<State>NY</State>
<Zip>10542</Zip>
</CustomerAddress>
<CustomerProducts>
<CustomerProduct>
<PoductType>REC</PoductType>
<ProductNumber>2050920400</ProductNumber>
</CustomerProduct>
</CustomerProducts>
</Customer>
</NewYorkCustomers>
</USACustomers>
代码
SELECT
CustomerName,
CustomerDOB,
CustomerEmail,
PoductType
FROM XMLTABLE ( '/USACustomers/NewYorkCustomers/Customer/CustomerProducts/CustomerProduct'
PASSING xmltype (BFILENAME ('BACKUP', 'TEST.xml'), NLS_CHARSET_ID ('AL32UTF8'))
COLUMNS CustomerName VARCHAR2(50) PATH 'CustomerData/CustomerName',
CustomerDOB VARCHAR2(50) PATH 'CustomerData/CustomerDOB',
CustomerEmail VARCHAR2(50) PATH 'CustomerData/CustomerEmail',
PoductType VARCHAR2(50) PATH 'PoductType',
ProductNumber VARCHAR2(50) PATH 'ProductNumber');