I have a List which has a list type property (Address) inside it. I am sending the whole information as an xml in database to update/insert the details in my oracle table.
Here is the 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
FOR xmlrow IN
(SELECT column_value AS xml
FROM TABLE(XMLSequence(x.extract('/person/row')))
)
LOOP
SELECT extractValue(xmlrow,'/row/name/text()')
INTO v_person_name
FROM dual;
DBMS_OUTPUT.put_line(v_person_name);
FOR address IN
(SELECT column_value AS xml
FROM TABLE(xmlsequence(xmlrow.extract('/row/Address/LocalAddress')))
)
LOOP
-- extract address values same as above.
SELECT extractValue(xmlrow,'/LocalAddress/City/text()')
INTO v_city
FROM dual;
DBMS_OUTPUT.put_line(v_city);
END LOOP;
END LOOP;
END;
How can I parse this whole xml in oracle? I am sending this as xmltype variable.
It is giving me a comilation error
Error report -
ORA-06550: line 35, column 27:
PLS-00382: expression is 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 be declared
ORA-06550: line 41, column 37:
PLS-00302: component 'EXTRACT' must be 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: expression is 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: Usually a PL/SQL compilation error.
Please help me to resolve this. Thanks in advance.