Reputation: 11
I have an oracle table which has a column that stores XML. The XML has the following syntax:
<?xml version="1.0"?>
<MessageData>
<TextblockParameters>
<TextblockParameter>
<tagName>BUSINESSPROCESSID</tagName>
<value>RETAIL</value>
</TextblockParameter>
<TextblockParameter>
<tagName>SEGMENT</tagName>
<value>RESIDENTIAL</value>
</TextblockParameter>
<TextblockParameter>
<tagName>TRANSACTIONTYPE</tagName>
<value>PURCHASE</value>
</TextblockParameter>
<TextblockParameter>
<tagName>LANGUAGE</tagName>
<value>EST</value>
</TextblockParameter>
</TextblockParameters>
</MessageData>
Now i need to get info from <value></Value>
, from all 4 places. Please help with this issue, dont know if Extractvalue is best solution
Upvotes: 1
Views: 1917
Reputation: 272006
You can use XMLTABLE
function for this (see examples):
SELECT t.foo, xt.*
FROM t, XMLTABLE('//TextblockParameter'
PASSING t.xmlcol
COLUMNS
tagName VARCHAR2(100) PATH './tagName',
value VARCHAR2(100) PATH './value'
) xt;
Upvotes: 4
Reputation: 30545
you can use
select extract(col1, '//value') from t;
create table t (col1 xmltype);
✓
insert into t values (' <MessageData> <TextblockParameters> <TextblockParameter> <tagName>BUSINESSPROCESSID</tagName> <value>RETAIL</value> </TextblockParameter> <TextblockParameter> <tagName>SEGMENT</tagName> <value>RESIDENTIAL</value> </TextblockParameter> <TextblockParameter> <tagName>TRANSACTIONTYPE</tagName> <value>PURCHASE</value> </TextblockParameter> <TextblockParameter> <tagName>LANGUAGE</tagName> <value>EST</value> </TextblockParameter> </TextblockParameters> </MessageData>');
1 rows affected
select extract(col1, '//value') from t;
| EXTRACT(COL1,'//VALUE') | | :------------------------------------------------------------------------------------------------------- | | <value>RETAIL</value><br><value>RESIDENTIAL</value><br><value>PURCHASE</value><br><value>EST</value><br> |
db<>fiddle here
Upvotes: -1