Question : How to extract data from oracle xmltype

Using this sql I can extract one value from the xml
 select extractvalue(my_xml, '//ComponentCommId')
from junk_xml2;  -- yields abc2::2AAS-W-018

But I can't figure out the syntax to get data from nodes below the root.  Especially if they are repeating.
select extract(my_xml, '//Status/StatusTypeCommId')
from junk_xml;  -- yields (null)

The single/double/no slash is confusing me and how to handle repeating node
I also tried
select extract(my_xml, '/Status/StatusTypeCommId[position()=2]')
from junk_xml2;  -- yields null

   <ns0:Status>
        <StatusTypeCommId>Latest(Revision), Latest(Approved) and Effective (in that range)</StatusTypeCommId>
        <StatusTypeName>TagStatus</StatusTypeName>
    </ns0:Status>
    <ns0:Status>
        <StatusTypeCommId>O</StatusTypeCommId>
        <StatusTypeName>OperationalStatus</StatusTypeName>
    </ns0:Status>

A followon question is how to pull out a value from the system instruction which uses a different namespace
select extract(my_xml, '//SystemInstruction/TransactionID','xmlns:ns1="http://www.constellation.com/CGG/WorkInventoryManagement/CBO/SystemInstruction"' ) from junk_xml2; -- yielded null

Any examples would be great! or a good place to find examples.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
-- sample table/data
  CREATE TABLE "EBFCMS"."JUNK_XML2" 
   (	"MY_COMMENT" VARCHAR2(4000 BYTE), 
	"MY_XML" XMLTYPE
   );


set define off;

DECLARE 
    myclob CLOB;
BEGIN
    myclob := '<?xml version="1.0" encoding="UTF-8"?>
<ns0:Component xmlns:ns0="http://www.mysite.com/WIM/CBO/1.0/Component">
    <ns0:Status>
        <StatusTypeCommId>Latest(Revision), Latest(Approved) and Effective (in that range)</StatusTypeCommId>
        <StatusTypeName>TagStatus</StatusTypeName>
    </ns0:Status>
    <ns0:Status>
        <StatusTypeCommId>O</StatusTypeCommId>
        <StatusTypeName>OperationalStatus</StatusTypeName>
    </ns0:Status>
    <ns0:ComponentTrain>
        <TrainCommId/>
        <TrainName/>
    </ns0:ComponentTrain>
    <ns0:ComponentChannel>
        <ChannelCommId>2</ChannelCommId>
        <ChannelName/>
    </ns0:ComponentChannel>
    <ns0:ComponentVersion>
        <ComponentVersionCommId>1</ComponentVersionCommId>
        <ComponentVersionName>000</ComponentVersionName>
    </ns0:ComponentVersion>
    <ns0:Location>
        <LocationCommId/>
        <LocationTypeCommId>CONTROL</LocationTypeCommId>
        <LocationTypeName/>
    </ns0:Location>
    <ns0:System>
        <ns0:SystemFunction>
            <FunctionTypeCommId>AAS</FunctionTypeCommId>
            <FunctionTypeName>BREATHING AIR</FunctionTypeName>
        </ns0:SystemFunction>
        <SystemCommId>AIR</SystemCommId>
        <SystemName>AIR</SystemName>
        <SubSystemCommId>AAS</SubSystemCommId>
        <SubSystemName>BREATHING AIR</SubSystemName>
    </ns0:System>
    <ns0:SafetyClass>
        <SafetyClassCommId>Safety Related</SafetyClassCommId>
        <SafetyClassName/>
    </ns0:SafetyClass>
    <ns0:SafetyCategory>
        <SafetyCategoryCommId>Not Applicable</SafetyCategoryCommId>
        <SafetyCategoryName>Safety_Category_abc</SafetyCategoryName>
    </ns0:SafetyCategory>
    <ns0:SafetyFunction>
        <SafetyFunctionCommId/>
        <SafetyFunctionName/>
        <SafetyFunctionDescription/>
    </ns0:SafetyFunction>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>Q.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385317</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::Q.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>R.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385318</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::R.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>S.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385319</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::S.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>T.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385320</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::T.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>U.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385321</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::U.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>V.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385322</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::V.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>W.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385323</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::W.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>X.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385324</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::X.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>Y.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385325</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::Y.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>N</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>Z.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4385326</DocumentSysId>
            <DocumentCommId>075205029::abc2-PGCC::Z.00</DocumentCommId>
            <LegacyDocumentCommId>075205029</LegacyDocumentCommId>
            <DocumentTitle>WIRE LIST U700</DocumentTitle>
            <DocumentClassTypeCommId>abc2-PGCC</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ns0:ComponentDocument>
        <ns0:Document>
            <ns1:Status xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <StatusTypeCommId>A</StatusTypeCommId>
                <StatusTypeName>Status</StatusTypeName>
            </ns1:Status>
            <ns1:DocumentRevision xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Document">
                <DocumentRevisionCommId>07.00</DocumentRevisionCommId>
            </ns1:DocumentRevision>
            <DocumentSysId>4166665</DocumentSysId>
            <DocumentCommId>07AAS001-002::abc2-ESK::07.00</DocumentCommId>
            <LegacyDocumentCommId>07AAS001-002</LegacyDocumentCommId>
            <DocumentTitle>BREATHING AIR CPRSR AUX</DocumentTitle>
            <DocumentClassTypeCommId>abc2-ESK</DocumentClassTypeCommId>
            <DocumentClassTypeName/>
        </ns0:Document>
    </ns0:ComponentDocument>
    <ComponentSysId>426269</ComponentSysId>
    <ComponentCommId>abc2::2AAS-W-018</ComponentCommId>
    <LegacyCommId>2AAS-W-018</LegacyCommId>
    <FacilityCommId>abc</FacilityCommId>
    <FacilityName/>
    <UnitCommId>2</UnitCommId>
    <UnitName/>
    <ComponentTypeCommId>Electrical conductors</ComponentTypeCommId>
    <ComponentTypeName/>
    <ComponentSubtypeCommId>Cable</ComponentSubtypeCommId>
    <ComponentShortDescription>CABLE</ComponentShortDescription>
    <ComponentLongDescription>CABLE </ComponentLongDescription>
    <FireAreaTypeCommId/>
    <FireZoneTypeCommId/>
    <InServiceTestTypeCommId>No</InServiceTestTypeCommId>
    <InServiceInspectionTypeCommId>No</InServiceInspectionTypeCommId>
    <SeismicTriIndicator>No</SeismicTriIndicator>
    <EnvironmentQualificationTriIndicator>Yes</EnvironmentQualificationTriIndicator>
    <MechanicalQualificationTriStateIndicator>No</MechanicalQualificationTriStateIndicator>
    <ContainingCobaltSteliteTriIndicator/>
    <BoricAcidTriIndicator>Indeterminate</BoricAcidTriIndicator>
    <Alloy600TriIndicator>Indeterminate</Alloy600TriIndicator>
    <AppendixJTriIndicator>No</AppendixJTriIndicator>
    <RegGuide197Indicator/>
    <LicenseRenewalIndicator/>
    <LicenseRenewalSystemEvaluatedIndicator/>
    <AgingManagementIndicator/>
    <MOVProgramIndicator/>
    <AOVProgramIndicator/>
    <AppRIndicator/>
    <FireProgramIndicator/>
    <NFPA805Indicator/>
    <PRACategoryIndicator/>
    <EmergencyPlanningIndicator/>
    <LossNormalHeatRemovalIndicator/>
    <SinglePointVulnerabilityIndicator/>
    <POMSIndicator/>
    <MaintenanceRuleIndicator/>
    <LatentInformationIndicator/>
    <FloodBarrierProgramIndicator/>
    <DigitalDeviceIndicator/>
    <LogicSystemFunctionalTestIndicator>Indeterminate</LogicSystemFunctionalTestIndicator>
    <ServiceWaterSystemOptimizationIndicator/>
    <ns0:AnyComponentAttribute>
        <ns1:ComponentAttributes xmlns:ns1="http://www.mysite.com/WIM/CBO/1.0/Component_Ext.xsd">
            <HumanFactors>Indeterminate</HumanFactors>
        </ns1:ComponentAttributes>
    </ns0:AnyComponentAttribute>
    <ns0:SystemInstruction>
        <ns1:SystemInstruction xmlns:ns1="http://www.mysite.com/WIM/CBO/SystemInstruction">
            <ns1:TransactionID>248159</ns1:TransactionID>
            <ns1:Source>AEBMEL</ns1:Source>
            <ns1:URL>
                <ns1:Host>aeb-146.xxx.corp.net</ns1:Host>
                <ns1:Port>80</ns1:Port>
                <ns1:Protocol>HTTP</ns1:Protocol>
                <ns1:URLPath>aeBWeb/PlugIns/TagManager/Shared/Display.aspx</ns1:URLPath>
                <ns1:QueryString>t=212&amp;o=426269</ns1:QueryString>
            </ns1:URL>
        </ns1:SystemInstruction>
    </ns0:SystemInstruction>
</ns0:Component>
';

INSERT INTO junk_xml2 VALUES ('test1', XMLTYPE(myclob));
COMMIT;

END;

Answer : How to extract data from oracle xmltype

Also, if you want to go after specific ones in a specific namespace you can add a namespace parameter to the extract:

select extractvalue(column_value,'*') myText
from junk_xml2 j, table(xmlsequence(extract(my_xml, '/ns0:Component/ns0:Status/StatusTypeCommId','xmlns:ns0="http://www.mysite.com/WIM/CBO/1.0/Component"')))
/




Random Solutions  
 
programming4us programming4us