To extract the value of a tag from the given XML-like string in PL/SQL, you can use the EXTRACTVALUE
function or XMLTABLE
for XML processing.
Example Using EXTRACTVALUE
DECLARE
xml_data CLOB := '<Status>200</Status><Message>Success</Message>';
l_message VARCHAR2(50);
BEGIN
-- Extract the FunctionalReferenceID value
l_message := EXTRACTVALUE(XMLTYPE('<root>' || xml_data || '</root>'), '/root/Message');
-- Print the value
DBMS_OUTPUT.PUT_LINE('FunctionalReferenceID: ' || l_message);
END;
Example Using XMLTABLE
DECLARE
xml_data CLOB := '<Status>200</Status><Message>Success</Message>';
l_message VARCHAR2(50);
BEGIN
-- Use XMLTABLE to extract the Message
SELECT value
INTO l_message
FROM XMLTABLE(
'/root/Message'
PASSING XMLTYPE('<root>' || xml_data || '</root>')
COLUMNS value VARCHAR2(50) PATH '.'
);
-- Print the value
DBMS_OUTPUT.PUT_LINE('Message: ' || l_message);
END;
What are your thoughts on this post?
I’d love to hear from you! Click this link to email me—I reply to every message!
Also use the share button below if you liked this post. It makes me smile, when I see it.