Oracle 10g: Extract data (select) from XML (CLOB Type)

mymark picture mymark · Feb 3, 2011 · Viewed 106k times · Source

I'm new in Oracle and I've - maybe trivial - a problem in a select. (I'm using Oracle 10g Express Edition).

I've a DB with a field CLOB: mytab.xml This column have an XML like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<info>
<id> 954 </id>
<idboss> 954 </idboss>
<name> Fausto </name>
<sorname> Anonimo </sorname>
<phone> 040000000 </phone>
<fax> 040000001 </fax>
</info>

I'm trying to do a 'simple' select to get, for example, the value of 'fax' tag. But I've a bit of problem and I'm not able to understand my error. For example:

select extract(xml, '//fax').getStringVal() from mytab;
ORA-00932: inconsistent datatypes: expected - got

select extract(xmltype(xml), '//fax').getStringVal() from mytab;
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYS.XMLTYPE", line 254

I've tryed also with 'extractvalue', but I've the same problems. where I'm wrong to do this?

Answer

dogbane picture dogbane · Feb 3, 2011

Try this instead:

select xmltype(t.xml).extract('//fax/text()').getStringVal() from mytab t