【问题标题】:Extracting XML data from CLOB从 CLOB 中提取 XML 数据
【发布时间】:2015-09-08 20:09:33
【问题描述】:

如何从数据中提取 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>

【问题讨论】:

标签: sql xml oracle


【解决方案1】:

使用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

【讨论】:

  • 我如何使用 INNER JOIN 与另一个以 FOODITEMID 为主键的表。@Eat Å Peach
  • 将其用作内联视图或 CTE。例如:select * from (&lt;above query&gt;) a inner join other_table b on b.fooditemid = a.fooditemid;
猜你喜欢
  • 2015-06-12
  • 2015-11-21
  • 2015-07-24
  • 1970-01-01
  • 1970-01-01
  • 2019-07-29
  • 2014-01-04
  • 2011-06-20
  • 2018-02-23
相关资源
最近更新 更多