title: How to Extract xmltype as xml in Oracle
body: <p>I am trying to extract xml from the <code>xmltype</code> doc.</p>
  
  <pre><code>DECLARE
    xmlData         XMLType;
    sDocumentId     VARCHAR2(100);
    sFormat         VARCHAR2(100);
    cData           CLOB;
  BEGIN
    xmlData := XMLType( '&lt;main&gt;
                        &lt;document_id&gt;1234567&lt;/document_id&gt;
                        &lt;format&gt;E66&lt;/format&gt;
                        &lt;data&gt;&lt;Fname&gt;ABCD&lt;/Fname&gt;&lt;Lname&gt;EFGD&lt;/Lname&gt;&lt;/data&gt;
                    &lt;/main&gt;');
  
    SELECT ExtractValue(xmlData, '/main/document_id/text()'),
           ExtractValue(xmlData, '/main/format/text()'),
           ExtractValue(xmlData, '/main/data/text()')
    INTO sDocumentId,
         sFormat,
         cData
    FROM (SELECT xmlData  FROM DUAL);
  
    dbms_output.put_line(sDocumentId);
    dbms_output.put_line(sFormat);
    dbms_output.put_line(cData);
  END;
  </code></pre>
  
  <p>How to get the output like this:</p>
  
  <ul>
  <li>DocumentId = <code>1234567</code></li>
  <li>sFormat = <code>E66</code></li>
  <li>cData = <code>&lt;Fname&gt;ABCD&lt;/Fname&gt;&lt;Lname&gt;EFGD&lt;/Lname&gt;</code></li>
  </ul>