Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the target table:</p> <pre><code>CREATE TABLE my_test ( LastName varchar2(20), phone NUMBER, code varchar2(20), address VARCHAR2(100) ); </code></pre> <p>The code to populate it:</p> <pre><code>SET serveroutput ON DECLARE l_xml xmltype; l_val VARCHAR2(1000) := '&lt;begin&gt; &lt;entry&gt; &lt;lastname&gt;gordon&lt;/lastname&gt; &lt;numberlist&gt; &lt;number&gt;100&lt;/number&gt; &lt;codelist&gt; &lt;code&gt;213&lt;/code&gt; &lt;/codelist&gt; &lt;/numberlist&gt; &lt;address&gt; &lt;addresslist&gt;jl. jalan pelan-pelan ke bekasi, indonesia&lt;/addresslist&gt; &lt;/address&gt; &lt;/entry&gt; &lt;entry&gt; &lt;lastname&gt;mark&lt;/lastname&gt; &lt;address&gt; &lt;addresslist&gt;jl. jalan cepet-cepet ke jakarta, indonesia&lt;/addresslist&gt; &lt;/address&gt; &lt;/entry&gt; &lt;/begin&gt;'; l_lastname varchar2(50); l_phone number; l_code number; l_address varchar2(200); BEGIN l_xml := xmltype(l_val); FOR x IN (SELECT VALUE(p) col_val FROM TABLE(XMLSEQUENCE(EXTRACT(l_xml, '/begin/entry'))) p ) loop IF x.col_val.existsnode('/entry/lastname/text()') &gt; 0 THEN l_lastname := x.col_val.extract('/entry/lastname/text()').getstringval(); END IF; if x.col_val.existsnode('/entry/numberlist/number/text()') &gt; 0 then l_phone := x.col_val.extract('/entry/numberlist/number/text()').getstringval(); end if; if x.col_val.existsnode('/entry/numberlist/codelist/code/text()') &gt; 0 then l_code := x.col_val.extract('/entry/numberlist/codelist/code/text()').getstringval(); end if; IF x.col_val.existsnode('/entry/address/addresslist/text()') &gt; 0 THEN l_address := x.col_val.extract('/entry/address/addresslist/text()').getstringval(); end if; INSERT INTO my_test ( lastname, phone, code, address ) VALUES ( l_lastname, l_phone, l_code, l_address ); l_lastname := null; l_phone := null; l_code := null; l_address := null; end loop; commit; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload