如何从数据中提取Food ItemID和Food Item Name and Quantity,如下所述。这是在plsql中的clob列。
<ServiceDetails>
<FoodItemDetails>
<FoodItem FoodItemID="6486" FoodItemName="CARROT" Quantity="2" Comments="" ServingQuantityID="142" ServingQuantityName="SMALL GLASS" FoodItemPrice="50" ItemDishPriceID="5336" CurrencyName="INR" Currency Id="43"/>
</FoodItemDetails>
<BillOption>
<Bill Details Total Price="22222" BillOption="cash"/>
</BillOption>
<Authoritativeness/>
</Service Details>
答案 0 :(得分:0)
使用xmltable。
数据设置:
create table myt(
col1 clob
);
insert into myt values('<ServiceDetails>
<FoodItemDetails>
<FoodItem FoodItemID="6486" FoodItemName="CARROT" Quantity="2" Comments="" ServingQuantityID="142" ServingQuantityName="SMALL GLASS" FoodItemPrice="50" ItemDishPriceID="5336" CurrencyName="INR" CurrencyId="43"/>
</FoodItemDetails>
<BillOption>
<BillDetails TotalPrice="22222" BillOption="cash"/>
</BillOption>
<Authoritativeness/>
</ServiceDetails>'
);
commit;
查询:
select cols.*
from myt
cross join xmltable('ServiceDetails/FoodItemDetails/FoodItem' passing xmltype(col1)
columns fooditemid varchar2(10) path '@FoodItemID',
fooditemname varchar2(20) path '@FoodItemName'
) cols;
结果:
FOODITEMID FOODITEMNAME
---------- --------------------
6486 CARROT