Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extract XML data from PLSQL

858328May 18 2016 — edited May 27 2016

Hi Allo,

I am trying to extract the value from XML by using below anonymous block,but getting errors.Please see the error report below.

Please advise.

DECLARE

  x XMLType := XMLType(

    '<?xml version="1.0" ?>

<abl:person>

   <abl:row>

       <abl:name>Jerry</abl:name>

       <abl:Address>

           <abl:State>UK</abl:State>

           <abl:City>London</abl:City>

       </abl:Address>

</abl:person>');

BEGIN

  FOR r IN (

    SELECT ExtractValue(Value(p),'/abl:row/abl:name/text()') as name

          ,ExtractValue(Value(p),'/abl:row/abl:Address/abl:State/text()') as state

          ,ExtractValue(Value(p),'/abl:row/abl:Address/abl:City/text()') as city

    FROM   TABLE(XMLSequence(Extract(x,'/person/row'))) p

    ) LOOP

    dbms_output.put_line(r.name||r.state||r.city);

    end loop;

END;

Error report -

-----------------

ORA-31011: XML parsing failed

ORA-19202: Error occurred in XML processing

LPX-00234: namespace prefix "abl" is not declared

Error at line 2

ORA-06512: at "SYS.XMLTYPE", line 301

ORA-06512: at line 2

31011. 00000 -  "XML parsing failed"

*Cause:    XML parser returned an error while trying to parse the document.

*Action:   Check if the document to be parsed is valid.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 24 2016
Added on May 18 2016
9 comments
546 views