XQuery example 1

Previous Next

This example retrieves (in an XML format) all scheduled tours due to start after the current date.

SELECT to_clob(
rdbms.xmltype.getclobval(
rdbms.XMLQuery(
LITERAL ' ''<Tours>
{for $c in ora:view("SCHEDTOUR")/ROW
WHERE $c/START_DATE > current-date()
RETURN <Tour>(<Name>{$c/DESTINATION/text()}</Name>,<StartDate>{$c/START_DATE/text()}</StartDate>,<EndDate>{$c/RETURN_DATE/text()}</EndDate>,<Price>{$c/PRICE/text()}</Price>)</Tour>}
</Tours>''  PASSING SYSDATE AS "s" RETURNING CONTENT'
)
)
)

The result is:

<Tours>
  <Tour>
    <Name>EUROPE</Name>
    <StartDate>2008-05-01</StartDate>
    <EndDate>2008-05-21</EndDate>
    <Price>1250</Price>
  </Tour>
  <Tour>
    <Name>AUSTRALIA</Name>
    <StartDate>2007-10-30</StartDate>
    <EndDate>2007-11-10</EndDate>
    <Price>2500</Price>
  </Tour>
</Tours>