我有一個列表,裏面有一個列表類型屬性(地址)。我發送整個信息作爲數據庫中的XML來更新/插入我的oracle表中的細節。解析存儲過程中的xml oracle
這裏是XML格式
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;
如何可以解析:在Oracle中整個XML?我發送這個xmltype變量。
這是給我一個comilation錯誤
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.
請幫我解決這個問題。 在此先感謝。
感謝解析嵌套的XML,但如何提取地址部分。 – user1685652
只需使用XPath即可。所以extractValue(column_value,'/ row/Address/LocalAddress/State/text()')等等。 – Nick
它是一個動態的XML,我不知道有多少本地地址我可以得到內部地址。 – user1685652