How do you extract a tag from a XML
Using XML DATA
Below is a Sample
declare
xml_data xmltype;
destination_var varchar2(2000);
destination_num number;
begin
xml_data:=xmltype('<tag><char>Some text</char><num>123</num></tag>');
destination_var := xml_data.extract('/tag/cha r/text()') .getString Val;
destination_num := xml_data.extract('/tag/num /text()'). getNumberV al;
dbms_output.put_line('/tag /char ' ||destination_var);
dbms_output.put_line('/tag /num ' ||destination_num);
end;
Would give the below Output
/tag/char Some text
/tag/num 123
Sample for Having more than one node in XML
declare
xml_data xmltype;
destination_var varchar2(2000);
destination_num number;
begin
xml_data:=xmltype('<tag><char>Some text</char><num>123</num><char>Next text</char><num>987</num></tag>');
destination_var := xml_data.extract('/tag/cha r/text()') .getString Val;
destination_num := xml_data.extract('/tag/num /text()'). getNumberV al;
dbms_output.put_line('/tag /char ' ||destination_var);
dbms_output.put_line('/tag /num ' ||destination_num);
end;
Would give the below output
/tag/char Some textNext text
/tag/num 123987
Using XML DATA
Below is a Sample
declare
xml_data xmltype;
destination_var varchar2(2000);
destination_num number;
begin
xml_data:=xmltype('<tag><char>Some text</char><num>123</num></tag>');
destination_var := xml_data.extract('/tag/cha
destination_num := xml_data.extract('/tag/num
dbms_output.put_line('/tag
dbms_output.put_line('/tag
end;
Would give the below Output
/tag/char Some text
/tag/num 123
Sample for Having more than one node in XML
declare
xml_data xmltype;
destination_var varchar2(2000);
destination_num number;
begin
xml_data:=xmltype('<tag><char>Some text</char><num>123</num><char>Next text</char><num>987</num></tag>');
destination_var := xml_data.extract('/tag/cha
destination_num := xml_data.extract('/tag/num
dbms_output.put_line('/tag
dbms_output.put_line('/tag
end;
Would give the below output
/tag/char Some textNext text
/tag/num 123987
No comments:
Post a Comment