Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issues extracting attributes from XMLtype column

889187Sep 19 2011 — edited Oct 5 2011
I am having trouble extracting values from a XML datatype column. There are 16 fields and when I try to extract the data the XML extract is returning all of them into 1 big return value. I having been trying everything but the problem seems to be that the field name is an attribute and everything I try fails. I appreciate any help in advance and I am extremely new to XML so please let me know if you need more info.

Using Oracle 11.2.0.2 Express

--Created table that has a column of XMLTYPE OF CLOB
CREATE TABLE HR.XMLTABLESTORE (key_id VARCHAR2(10) PRIMARY KEY, xmlloaddate date, xml_column XMLTYPE) XmlType xml_column STORE AS CLOB;

--Insert the XML into the column
INSERT INTO HR.XMLTABLESTORE VALUES (HR.XMLSEQUENCE.NEXTVAL, SYSDATE, XMLType(bfilename('XMLDIRX', 'PROD_20110725_211550427_220b.xml'),
nls_charset_id('AL32UTF8')));

I am succesfully getting the values for

SELECT extract(xml_column, '//MapItem/@ProductNum') ProductNum from FROM HR.XMLTABLESTORE

'63481062975'

Unsuccesfully getting the data under the field name as it is returning all the names or values

SELECT extract(xml_column, '//MapItem/Field/@Name') FROM HR.XMLTABLESTORE

'lowDispUnitsPerPackdosageFormmedicaidUnitTypemedicareUnitTypemedicareUnitsPerPackunitConversiontypeunitMeasurepricingUnitMeasurelabelerCodeproductNumdescriptionlongDescriptiondesiIndicatorgenericBrandTypeendoOrgCode'

How do I return one row of data at a time for the name and the value?

<?xml version = '1.0'?><Entries>
<Category ProductNum="634810629" NDC="634810629" Name="634810629" Ndc9Flag="true">
<Field Name="type" Type="java.lang.String" Value="Category"/>
<Field Name="productNum" Type="java.lang.String" Value="634810629"/>
<MapItem ProductNum="63481062975" NDC="63481062975" Ndc9Flag="false" Name="PERCOCET 10/325MG x 100 UD" Status="0" Description="PERCOCET 10/325MG x 100 UD" MedicaidUnitsPerPack="100.0" MarketEntryDate="2001-11-23 00:00:00" FirstSalesDate="2001-11-23 00:00:00" fdaApprovalDate="2001-11-23" fdaRegName="000000006348162975" ManuTermDate="2003-09-30 00:00:00" ShelfLifeExpDate="2003-09-30 00:00:00" drugType="Rx" DrugCategory="N" TheraCode="NR" EligibleForVA="false" EligibleForPHS="false" EligibleForASP="false" EligibleForMedicaid="true" NonCmtyPharmaDrug="false">
*<Field Name="lowDispUnitsPerPack" Type="java.lang.String" Value="1.000"/>*
*<Field Name="dosageForm" Type="java.lang.String" Value="TAB"/>*
*<Field Name="medicaidUnitType" Type="java.lang.String" Value="TAB"/>*
*<Field Name="medicareUnitType" Type="java.lang.String" Value="TAB"/>*
*<Field Name="medicareUnitsPerPack" Type="java.lang.String" Value="100.0"/>*
*<Field Name="unitConversion" Type="java.lang.String" Value="1"/>*
*<Field Name="type" Type="java.lang.String" Value="Item"/>*
*<Field Name="unitMeasure" Type="java.lang.String" Value="EA"/>*
*<Field Name="pricingUnitMeasure" Type="java.lang.String" Value="EA"/>*
*<Field Name="labelerCode" Type="java.lang.String" Value="63481"/>*
*<Field Name="productNum" Type="java.lang.String" Value="63481062975"/>*
*<Field Name="description" Type="java.lang.String" Value="PERCOCET 10/325MG x 100 UD"/>*
*<Field Name="longDescription" Type="java.lang.String" Value="PERCOCET 10/325MG x 100 UD"/>*
*<Field Name="desiIndicator" Type="com.modeln.bp.catalog.CMnDesiDrugIndicator" Value="2"/>*
*<Field Name="genericBrandType" Type="com.modeln.bp.struct.contract.enums.CMnGenericBrandItemType" Value="BRND"/>*
*<Field Name="endoOrgCode" Type="java.lang.String" Value="0010"/>*
</MapItem>
</Category>
</Entries>

Thanks,
Shawn
This post has been answered by AlexAnd on Sep 20 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2011
Added on Sep 19 2011
15 comments
4,396 views