如果PartNumber =“926-AA”,如何选择值“USPrice”?
我的选择总是以ORA-19025结束!
SELECT extractValue(OBJECT_VALUE, '/PurchaseOrder/Items/Item/USPrice/text()') "PRICE" FROM TMP_TABLE
WHERE extractValue(OBJECT_VALUE,'/PurchaseOrder/Items/Item[@PartNumber]') = '926-AA';
这是DDL:
CREATE TABLE TMP_TABLE OF XMLType;
INSERT INTO TMP_TABLE VALUES (XMLType(bfilename('XMLDIR', 'purchaseOrder.xml'),nls_charset_id('AL32UTF8')));
以下是数据:
<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
<Address Type="Shipping">
<Name>Ellen Adams</Name>
<Street>123 Maple Street</Street>
<City>Mill Valley</City>
<State>CA</State>
<Zip>10999</Zip>
<Country>USA</Country>
</Address>
<Address Type="Billing">
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<State>PA</State>
<Zip>95819</Zip>
<Country>USA</Country>
</Address>
<DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
<Items>
<Item PartNumber="872-AA">
<ProductName>Lawnmower</ProductName>
<Quantity>1</Quantity>
<USPrice>148.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item PartNumber="926-AA">
<ProductName>Baby Monitor</ProductName>
<Quantity>2</Quantity>
<USPrice>39.98</USPrice>
<ShipDate>1999-05-21</ShipDate>
</Item>
</Items>
</PurchaseOrder>
提前谢谢
答案 0 :(得分:2)
听起来像你打算这样做:
select extractvalue(object_value, '/PurchaseOrder/Items/Item[@PartNumber="926-AA"]/USPrice/text()') price
from tmp_table;
或者,如果您有多个行,那么您最好使用XMLTABLE
,因为自{11}以来已弃用EXTRACTVALUE
:
select *
from tmp_table tt
cross join xmltable('/PurchaseOrder/Items/Item'
passing tt.object_value
columns partnumber varchar2(20) path '@PartNumber',
usprice number path 'USPrice') x
where x.partnumber = '926-AA';