Query Structure
A valid XML SELECT
command against a document model is of the form SELECT ... FROM ... WHERE ... ORDER BY ...
. The use of any other SELECT
command clause is not allowed.
A fully qualified name for an XML element is as follows:
"model"."document name".[path to element]."element name"
A fully qualified name for an attribute is as follows:
"model"."document name".[path to element]."element name".[@]"attribute name"
Partially qualified names for elements and attributes can be used if the partial name is unique.
FROM Clause
The FROM
clause specifies the document to generate. Document names resemble other virtual groups: "model"."document name"
.
Syntax Rules
- The
FROM
clause may only contain one unary clause specifying the desired document.
SELECT
Clause
The SELECT
clause determines which parts of the XML document are generated for output.
Here are some examples of the syntax:
- SQL
SELECT * FROM model.doc
- SQL
SELECT model.doc.root.parent.element.* FROM model.doc
- SQL
SELECT element, element1.@attribute FROM model.doc
Syntax Rules
SELECT *
andSELECT "xml"
are equivalent and specify that every element and attribute of the document should be output;- The
SELECT
clause of an XML query may only contain*
,"xml"
, or element and attribute references from the specified document. Any other expressions are not allowed; - If the
SELECT
clause contains an element or attribute reference (other than*
or"xml"
), only the specified elements, attributes, and their ancestor elements will be in the generated document; element.*
specifies that the element, its attribute, and all child content should be output.
WHERE Clause
The WHERE
clause specifies how to filter content from the generated document based upon values contained in the underlying mapping classes. Most predicates are valid in an XML SELECT
command. However, combining value references from different document parts may not always be allowed.
Criteria are logically applied to a context directly related to a mapping class. Starting with the root mapping class, there is a root context that describes all of the top levels repeated elements in the output document. Criteria applied to the root or any other context will change the related mapping class query to apply the effects of the criteria, which can include checking values from any of the descendant mapping classes.
Here are some examples of the syntax:
SELECT element, element1.@attribute FROM model.doc WHERE element1.@attribute = 1
SELECT element, element1.@attribute FROM model.doc WHERE context(element1, element1.@attribute) = 1
Syntax Rules
- Each criteria conjunct must refer to a single context and can be criteria that apply to a mapping class, contain a
rowlimit
function, or containrowlimitexception
function; - Criteria that apply to a mapping class are associated with that mapping class via the context function. The absence of a context function implies the criteria apply to the root context;
At a given context the criteria can span multiple mapping classes provided that all mapping classes involved are either parents of the context, the context itself, or a descendant of the context.
Sibling Root Mapping Classes
Implied root context user criteria against a document model with sibling root mapping classes are not generally semantically correct. It is applied as if each conjunct is applied to only a single root mapping class. This behaviour is the same as in prior releases but may be fixed in a future release.
XML SELECT Command-specific Functions
XML SELECT
Command functions resemble scalar functions, but act as hints in the WHERE
clause. These functions are only valid in an XML SELECT
command.
Context Function
CONTEXT(arg1, arg2)
Select the context for the containing conjunct.
Syntax Rules
- Context functions apply to the whole conjunct.
- The first argument must be an element or attribute reference from the mapping class to whose context the criteria conjunct will apply.
- The second parameter is the return value for the function.
rowlimit Function
This function limits the rows processed for the given context.
ROWLIMIT(arg)
Syntax Rules
- The first argument must be an element or attribute reference from the mapping class whose context the row limit applies;
- The
rowlimit
function must be used in equality comparison criteria with the right-hand expression equal to a positive integer number or rows to limit; - Only one row limit or row limit exception may apply to a given context.
rowlimitexception Function
This function limits the rows processed for the given context and throws an exception if the number of rows is exceeded.
ROWLIMITEXCEPTION(arg)
Syntax Rules
- The first argument must be an element or attribute reference from the mapping class whose context the row limit exception applies;
- The
rowlimitexception
function must be used in equality comparison criteria with the right-hand expression equal to a positive integer number or rows to limit; - Only one-row limit or row limit exception may apply to a given context.
ORDER BY Clause
The XML SELECT
command's ORDER BY
clause specifies ordering for the referenced mapping class queries.
Syntax Rules
- Each order by item must be an element or attribute reference tied to an output value from a mapping class;
- The order or the order by items is the relative order they will be applied to their respective mapping classes.