(a) Function
Determines whether an XML type value, resulting from the evaluation of one or more XQuery arguments, is an XQuery sequence that is composed of one or more XQuery items.
(b) Format
XMLEXISTS (XQuery-query
PASSING BY VALUE XML-query-argument [, XML-query-argument]... )
XQuery-query ::= character-string-literal
XML-query-argument ::= {XML-query-context-items|XML-query-variable}
XML-query-context-items ::= value-expression [BY VALUE]
XML-query-variable ::= value-expression AS XQuery-variable-identifier [BY VALUE] |
(c) Operands
- XQuery-query ::= character-string-literal
Specifies the XQuery query to evaluate as a character string literal. For details about how to specify XQuery queries, see 1.15 XQuery.
- XML-query-argument ::= {XML-query-context-items|XML-query-variable}
Specifies the argument to pass to the XQuery query.
The parent properties of the XQuery sequence items that are passed to the XQuery query as the XML query argument are empty. If you code nodes representing the same part of the same XML type value in XQuery sequences specified in different XML query arguments, they are treated as different nodes in the XQuery evaluation.
- XML-query-context-items ::= value-expression [BY VALUE]
Specifies the context items to be evaluated for the XQuery query.
If not specified, the XQuery query specified in XQuery-query is evaluated once, and no context items are set.
Note that only one such item can be specified in the PASSING clause.
- value-expression
- Specifies a value expression whose result evaluates to an XML type value.
- Each XQuery item in the sequence that makes up the XML type value that results from this value expression will be a context item in the XQuery evaluation.
- If the result of the value expression is the null value, the XMLEXISTS predicate is undefined.
- The following can be specified:
- Column specification
- Column from a named derived table that was derived from a column specification
- BY VALUE
- This format is supported only for compatibility with ISO standards. It has no effect on how a value resulting from a value expression specified in an XML query context item is returned.
- XML-query-variable ::= value-expression AS XQuery-variable-identifier [BY VALUE]
Specified in order to pass a value to an XQuery variable specified in the XQuery query.
- value-expression
- Specifies the value expression to pass to the XQuery variable specified in the XQuery query.
- If the result of the value expression is not the XML type, it is converted to an XQuery sequence whose value is the XML type before being passed.
- The following table lists the data types that can be specified and their formats after conversion.
Table 1-40 Data types of values passed to XQuery variables and their XML type value formats after conversion
Data type | Format after conversion |
---|
INTEGER | Value of type xs:int# |
SMALLINT | Value of type xs:int# |
DECIMAL | Value of type xs:decimal# |
FLOAT | Value of type xs:double# |
SMALLFLT | Value of type xs:double# |
CHAR | Value of type xs:string# |
VARCHAR | Value of type xs:string# |
MCHAR | Value of type xs:string# |
MVARCHAR | Value of type xs:string# |
DATE | Value of type xs:date# |
TIME | Value of type xs:time# |
TIMESTAMP | Value of type xs:dateTime# |
XML | Not converted (same format as the XML type value specified in the value expression) |
- #
- Becomes an XQuery sequence consisting of a single atomic value.
- An error results if the XQuery sequence cannot be converted.
- If the result of the value expression is the null value, the value passed to the XQuery variable is an empty XQuery sequence.
- The following can be specified in the value expression:
- Literal
- USER, CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP
- Column specification
- SQL variable or SQL parameter
- Arithmetic operation, date operation, time operation, or concatenation operation
- Scalar function
- Function invocation
- CASE expression
- CAST specification
- Embedded variable or ? parameter
- Scalar subquery
- Column from a named derived table that was derived from any of the above value expressions
- AS XQuery-variable-identifier
- Specifies the identifier of the XQuery variable to which the value is passed.
- The XQuery variable identifier specifies an XQuery variable name that is specified in the XQuery query. For details about specifying names, see 1.1.7 Specification of names.
- The XML namespace of the XQuery variable identifier specified here is the default XML namespace of the XQuery query.
- The effective scope of the XQuery variable corresponding to the XQuery variable identifier specified here is the entire XQuery query.
- You cannot specify XQuery variable identifiers that are specified in other XML query variables in the same PASSING clause.
- BY VALUE
- This format is supported only for compatibility with ISO standards. It has no effect on how a value resulting from a value expression specified in an XML query variable is returned.
- Specify this only if the result of the value expression is the XML type. An error results if the result of the value expression is not the XML type.
(d) Conditions under which predicate is TRUE
The XMLEXISTS predicate is TRUE if the resulting XML type value of the XQuery evaluation is an XQuery sequence consisting of one or more XQuery items.
(e) Rules
- This predicate can be specified only in a WHERE clause.
- It cannot be specified in a subquery.
(f) Example
Retrieve from BOOK_MANAGEMENT_TABLE the values of the book_id column in the rows stored in bookinfo where the price is greater than or equal to the value specified in the embedded variable :price.
SELECT book_id FROM BOOK_MANAGEMENT_TABLE
WHERE XMLEXISTS('/bookinfo[price>=$PRICE]'
PASSING BY VALUE bookinfo,
:price AS PRICE)