Variable references in XQuery

A variable reference is a QName that is preceded by a dollar sign ($). When an XQuery expression is evaluated, each variable reference resolves to the value of the expression that is bound to the variable.

Every variable reference must match a name in the in-scope variables for the XQuery expression. In-scope variables are bound from the SQL context that invokes the XQuery expression (XMLQUERY or XMLEXISTS).

Two variable references are equivalent if their local names are the same and their namespace prefixes are bound to the same namespace URI in the in-scope namespaces. An variable reference with no prefix is in no namespace.

Examples

In the following example, the XMLQUERY function binds the value of the host variable :IHV to $PARTNUMBER, and the value of column C1 to $QTY.
SELECT XMLQUERY('//item[@partNum = $PARTNUMBER and quantity=$QTY])'
  PASSING XMLPO, :IHV AS PARTNUMBER, C1 AS QTY)
FROM T1;