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!

Counting elements in XML based on search criteria

641220Jul 23 2010 — edited Jul 24 2010
Hi again,

I been trying to return a count of <c> in a specific <subno> element. I tried the below query but never worked. I managed to do it using XMLTABLE ( '/IN-prov/Subscriber/Subno[@Id="9393983"]/Commands/C'..etc without the node exists function. It works.. but the problem is, its not useful because i cannot change the number dynamically. When I tried it inside a PLSQL code and replaced it with XMLTABLE ( '/IN-prov/Subscriber/Subno[@Id="'||NUMBER||'"]/Commands/C'.. it returned an error because it cannot accept anything else but a string.. so, I tried the below approach with is not working yet..


WITH Param_Xml AS (SELECT xmltype('<IN-prov>
<Subscriber>
<Subno Id="9393983">
<Commands>
<C>
<Head>Head 1</Head>
<Value>Value of head one</Value>
</C>
<C>
<Head>Head 2</Head>
<Value>Value of head 2</Value>
</C>
<C>
<Head>Head 3</Head>
<Value>Value of head 3</Value>
</C>
</Commands>
</Subno>
<Subno Id="9393981">
<Commands>
<C>
<Head>Head 1</Head>
<Value>Value of head one</Value>
</C>
<C>
<Head>Head 2</Head>
<Value>Value of head 2</Value>
</C>
<C>
<Head>Head 3</Head>
<Value>Value of head 3</Value>
</C>
</Commands>
</Subno>
</Subscriber>
</IN-prov>') AS Xmlcol FROM DUAL)
SELECT count(*)
FROM Param_Xml, XMLTABLE ( '/IN-prov/Subscriber/Subno/Commands/C'
PASSING Xmlcol
) U
where existsnode(xmlcol, '/IN-prov/Subscriber[Subno/@Id="9393981"=1



Appreciate the help :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2010
Added on Jul 23 2010
3 comments
1,699 views