Parse xml in stored procedure oracle -
Parse xml in stored procedure oracle -
i have list has list type property (address) within it. sending whole info xml in database update/insert details in oracle table.
here xml format
declare x xmltype := xmltype( ' <person> <row> <name>tom</name> <address> <localaddress> <state>california</state> <city>los angeles</city> </localaddress> <localaddress> <state>california1</state> <city>los angeles1</city> </localaddress> </address> </row> <row> <name>jim</name> <address> <localaddress> <state>california</state> <city>los angeles</city> </localaddress> </address> </row> </person>'); v_person_name varchar2(1000); v_city varchar2(1000); begin xmlrow in (select column_value xml table(xmlsequence(x.extract('/person/row'))) ) loop select extractvalue(xmlrow,'/row/name/text()') v_person_name dual; dbms_output.put_line(v_person_name); address in (select column_value xml table(xmlsequence(xmlrow.extract('/row/address/localaddress'))) ) loop -- extract address values same above. select extractvalue(xmlrow,'/localaddress/city/text()') v_city dual; dbms_output.put_line(v_city); end loop; end loop; end;
how can parse whole xml in oracle? sending xmltype variable.
it giving me comilation error
error study - ora-06550: line 35, column 27: pls-00382: look of wrong type ora-06550: line 35, column 14: pl/sql: ora-00932: inconsistent datatypes: expected - got - ora-06550: line 35, column 7: pl/sql: sql statement ignored ora-06550: line 41, column 37: pls-00302: component 'extract' must declared ora-06550: line 41, column 37: pls-00302: component 'extract' must declared ora-06550: line 41, column 30: pl/sql: ora-00904: "xmlrow"."extract": invalid identifier ora-06550: line 40, column 7: pl/sql: sql statement ignored ora-06550: line 45, column 29: pls-00382: look of wrong type ora-06550: line 45, column 16: pl/sql: ora-00932: inconsistent datatypes: expected - got - ora-06550: line 45, column 9: pl/sql: sql statement ignored 06550. 00000 - "line %s, column %s:\n%s" *cause: pl/sql compilation error.
please help me resolve this. in advance.
i able parse nested xml using method
set serveroutput on format wrapped; declare x xmltype := xmltype(' <person> <row> <name>tom</name> <address> <localaddress> <state>california</state> <city>los angeles</city> </localaddress> <localaddress> <state>california1</state> <city>los angeles1</city> </localaddress> </address> </row> <row> <name>jim</name> <address> <localaddress> <state>california</state> <city>los angeles</city> </localaddress> </address> </row> </person>'); begin r in (select extractvalue(value(p),'/row/name/text()') name , extract(value(p),'/row/address') address table(xmlsequence(extract(x,'/person/row'))) p ) loop dbms_output.put_line(r.name); row1 in (select extractvalue(value(l),'/localaddress/city/text()') city table(xmlsequence(extract(r.address,'/address/localaddress'))) l ) loop dbms_output.put_line(row1.city); -- whatever want r.name, r.state, r.city end loop; -- whatever want r.name, r.state, r.city end loop; end;
xml oracle
Comments
Post a Comment