fn:distinct-values function
The fn:distinct-values function returns the distinct values in a sequence.
Syntax
- sequence-expression
- A sequence of atomic values, or the empty sequence. The items
in the sequence can have any of the following types:
- Numeric
- String
- Date or time types
Returned value
If sequence-expression is not the empty sequence, the returned value is a sequence that contains xs:string values that are the distinct values in sequence-expression. Two items are distinct if they are not equal to each other. XQuery uses the following rules to obtain a sequence of distinct values:
- If two values cannot be compared, those values are considered to be distinct.
- Values of type xs:untypedAtomic are compared using the rules for xs:string types.
- The order in which the sequence of values is returned might not be the same as the input order.
- The first value of a set of values that compare equal is returned.
- If sequence-expression is the empty sequence, the empty sequence is returned.
- For xs:double values, positive zero is equal to negative zero.
- If sequence-expression contains multiple NaN values, a single NaN value is returned.
Example
The following example returns the distinct values of node b:
SELECT XMLSERIALIZE(
XMLQUERY ('declare default element namespace
"http://posample.org";
fn:distinct-values($d/x/b)' PASSING XMLPARSE(DOCUMENT
'<x xmlns="http://posample.org">
<b>1</b><b>a</b><b>1.0</b><b>A</b><b>1</b></x>')
AS "d")
AS CLOB(1K) EXCLUDING XMLDECLARATION)
FROM SYSIBM.SYSDUMMY1 The returned value is ("1", "a", "1.0", "A").
