DB2 10.5 for Linux, UNIX, and Windows

Literals

A literal is a direct syntactic representation of an atomic value. DB2® 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 type xs:integer. For example, 12 is a numeric literal.
  • A numeric literal that contains a decimal point (.), but no e or E character is an atomic value of type xs:decimal. For example, 12.5 is a numeric literal.
  • A numeric literal that contains an e or E character is an atomic value of type xs:double. For example, 125E2 is a numeric literal.

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 single quotation marks (') or double quotation marks ("). String literals can include predefined entity references and character references. For example, the following strings are valid string literals:

"12.5"
"He said, ""Let it be."""
'She said: "Why should I?"'
"Ben & Jerry's"
"€65.50" (: denotes the string €65.50 :)
Tip: To include a single quotation mark within a string literal that is delimited by single quotation marks, specify two adjacent single quotation marks. Similarly, to include a double quotation mark within a string literal that is delimited by double quotation marks, specify two adjacent double quotation marks.

Within a string literal, line endings are normalized according to the rules for XML 1.0 (Third Edition). Any two-character sequence that contains a carriage return (X'0D') followed by a line feed (X'0A') is translated into a single line feed (X'0A'). Any carriage return (X'0D') that is not followed by a line feed (X'0A') is translated into a single line feed (X'0A').

If the value that you want to instantiate has no literal representation, you can use a constructor function or built-in function to return the value. The following functions and constructors return values that have no literal representation:

  • The built-in functions fn:true() and fn:false() return the boolean values true and false, respectively. These values can also be returned by the constructor functions xs:boolean("false") and xs:boolean("true").
  • The constructor function xs:date("2005-04-16") returns an item whose type is xs:date and whose value represents the date April 16, 2005.
  • The constructor function xdt:dayTimeDuration("PT4H") returns an item whose type is xdt:dayTimeDuration and whose value represents a duration of four hours.
  • The constructor function xs:float("NaN") returns the special floating-point value, "Not a Number."
  • The constructor function xs:double("INF") returns the special double-precision value, "positive infinity."