【发布时间】:2021-09-08 12:22:34
【问题描述】:
我有一个要求,我必须将 XML 表列选择为记录数据类型,它是静态数据类型和集合的组合。我搜索了各种说 Xpath 可以返回节点列表的来源,但我怀疑我是否可以使用列的集合数据类型来存储这个节点列表。
type MobileTable is Table of number Index by pls_integer;
type purchase is record (vegetables varchar2(20),fruits varchar2(30));
type food is table of purchase Index by pls_integer;
type data is record
(Name varchar2(30), Mobile_Number MobileTable,Purchases food);
<customers>
<month>July</month>
<day>Tuesday</day>
<start-time>11</start-time>
<customer>
<Name>sally</Name>
<Mobile-Number>999-256-00</Mobile-Number>
<Mobile-Number>999-256-11</Mobile-Number>
<purchase>
<vegetables>Carrot</vegetables>
<fruits>Apple</fruits>
</purchase>
<purchase>
<vegetables>Broccli</vegetables>
<fruits>Orange</fruits>
</purchase>
<customer>
</customers>
关于 XML 只是我用来解释我的需求的一个例子,如果问题不清楚,请提出。
我的查询:
select Name,Mobile_Number,Purchases into data from custommers_table ct,
xmltable('customers'
passing ct.cust_xml
columns Name varchar2(20) path 'Name',
Mobile_Number MobileTable path 'Mobile-Number',
Purchases food path '//purchase/vegetables|//purchase/fruit')
where cust_xml_id=1;
对于 Mobile_Number 和 Purchases,我收到了无效数据类型错误。
//purchase/vegetables|//purchase/fruit
我在 W3 学校的 Xpath 语法概念下找到了这个 XPath,我不确定它的正确性,但这是我想要实现的。
请建议我是否有其他方法可以实现这一目标。
【问题讨论】:
标签: sql oracle xpath xquery xmltable