select
XMLQuery('
<nums>
{
for $i in (1,1,2,3,5,8,13) return <num>{ $i }</num>
}
</nums>
' returning content).extract('//num[6]/text()').getStringVal() sixth_fibonacci_number
from
dual;
Arithmetical expressions
The following query returns 6:
drop table tq84_xml;
create table tq84_xml (
id number,
val clob
);
insert into tq84_xml values (1, '<nums>
<n>1</n><t>one</t>
<n>1</n><t>one</t>
<n>2</n><t>two</t>
<n>3</n><t>three</t>
<n>5</n><t>five</t>
<n>8</n><t>eight</t>
</nums>');
select
xmlQuery(
'
for $n in /nums/n
return <n-times-3> {
3 * xs:integer( $n ) (: use xs:integer to cast element value to appropriate type :)
} </n-times-3>'
passing xmlType(tq84_xml.val)
returning content
)
as x
from
tq84_xml;