Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
Using XSQL Servlet, 15 of 24
To use Oracle XSQL Pages for SQL queries, include <xsql:query> taga in your XML file wherever you want the SQL executed.
The <xsql:query> element is replaced by the XML output of your query. The XSQL Page Processor finds an attribute named connection on your XML document's element whose value must match the name of a connection defined in your XSQLConfig.xml file.
A simple example using <xsql:query> tag is:
<?xml version="1.0"?> <xsql:query xmlns:xsql="urn:oracle-xsql" connection="demo"> SELECT 'Hello World' AS "GREETING" FROM DUAL </xsql:query>
This produces the following XML document:
<?xml version = '1.0'?> <ROWSET> <ROW id="1"> <GREETING>Hello World</GREETING> </ROW> </ROWSET>
Any number pf <xsql:query> tags can be in an .xsql page. They can also be nested among other XML tags. But the .xsql must still be a well-formed XML document.
For example, you could build up a "data page" out of two queries like this:
<?xml version="1.0"?> <sales-by-year xmlns:xsql="urn:oracle-xsql" connection="salesdb"> <period id="H1" year="CY99"> <xsql:query> SELECT salesperson, SUM(sales) AS Total FROM sales WHERE sale_date between '01-JAN-99' and '30-JUN-99' GROUP BY salesperson </xsql:query> </period> <period id="H2" year="CY99"> <xsql:query> SELECT salesperson, SUM(sales) AS Total FROM sales WHERE sale_date between '01-JUL-99' and '31-DEC-99' GROUP BY salesperson </xsql:query> </period> </sales-by-year>
This gives the following results:
<?xml version="1.0"?> <sales-by-year connection="salesdb"> <period id="H1" year="CY99"> <ROWSET> <ROW id="1"> <SALESPERSON>Steve</SALESPERSON> <TOTAL>23465500</TOTAL> </ROW> <ROW id="2"> <SALESPERSON>Mark</SALESPERSON> <TOTAL>39983400</TOTAL> </ROW> </ROWSET> </period> <period id="H2" year="CY99"> <ROWSET> <ROW id="1"> <SALESPERSON>Steve</SALESPERSON> <TOTAL>67788400</TOTAL> </ROW> <ROW id="2"> <SALESPERSON>Mark</SALESPERSON> <TOTAL>55786990</TOTAL> </ROW> </ROWSET> </period> </sales-by-year>
You can customize many of the aspects of the XML query results produced for each <xsql:query> in your .xsql page by supplying one or more optional attributes on the appropriate <xsql:query> tag whose XML-results you'd like to affect.
The following attribute-based options correspond to features offered by the underlying oracle.xml.sql.query, OracleXMLQuery class. This class is provided in Oracle XML-SQL Utility (XSU) for Java
Table 19-4 lists the <xsql:query> tag attributes supported by the XSQL Page Processor. These are case-sensitive.
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|