Literals
XQuery supports two kinds of literals: numeric literals and string literals.
A numeric literal is an atomic value of type xs:integer
, xs:decimal
,
or xs:double
. A numeric literal that contains no
decimal point (.) and no e or E character is an atomic value of the
type xs:integer
. A numeric literal that contains
a decimal point (.), but no e or E character is an atomic value of
type xs:decimal
. A numeric literal that contains
an e or E character is an atomic value of type xs:double
.
Values of numeric literals are interpreted according to the rules
of XML Schema.
A string literal is an atomic value
of type xs:string
that is enclosed in delimiting
apostrophes or quotation marks. String literals can include predefined
entity references and character references.
To include an apostrophe within a string literal that is delimited by apostrophes, specify two adjacent apostrophes. Similarly, to include a quotation mark within a string literal that is delimited by quotation marks, specify two adjacent quotation marks.
If a string literal is used in an XQuery expression within the value of an XML attribute, the characters that are used to delimit the literal must be different from the characters that are used to delimit the attribute.
Examples
Example of an XQuery expression with numeric literals:
SELECT XMLQUERY ('7635') AS XSINTVAL,
XMLQUERY ('8735.98834') AS XSDECVAL,
XMLQUERY ('93948.87E+77') AS XSDOUBLEVAL
FROM T1;
This is the result:
XSINTVAL XSDECVAL XSDOUBLEVAL
-------- -------- -----------
7635 8735.98834 93948.87E+77
Example of an XQuery expression that contains a string literal with an embedded double quotation mark:
SELECT XMLQUERY ('"string literal double-quote "" in the middle"')
FROM T1
This is the result:
string literal double-quote " in the middle