XQuery Reference

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

XQuery Numeric Operators Reference

This chapter provides descriptions of the XQuery numeric operators available in the mapper functionality of WebLogic Workshop. You use the mapper functionality to generate queries and to edit these queries to add invocations to these provided XQuery operators. To learn more, see Invoking Functions or Operators in a Query.

In addition to the XQuery functions and operators available in the mapper functionality, a larger set functions and operators is provided. You can manually add invocations to these functions and operators to queries in the Source View of the mapper functionality. For a list of these additional functions and operators, see the XQuery 1.0 and XPath 2.0 Functions and Operators - W3C Working Draft 16 August 2002 available from the W3C Web site at the following URL:

http://www.w3.org/TR/2002/WD-xquery-operators-20020816

This section lists the numeric operators available from the mapper functionality:

op: decimal-add

Add $decimal-var1 to $decimal-var2. The + operator invokes the decimal-add operator.

Signatures

op:decimal-add(xs: decimal $decimal-var1, xs:decimal $decimal-var2) —> xs:decimal

Table 13-1 Arguments
Data Type
Argument
Description
xs:decimal
$decimal-var1
Represents a decimal number, for example: 1.1.
xs:decimal
$decimal-var2
Represents a decimal number, for example: 1.1.

Returns

Returns the decimal value of adding $decimal-var1 to $decimal-var2.

Examples
Simple

Invoking decimal-add("1.1","2.2") returns the decimal value 3.3 as shown in the following example query:

<decimal-add>{op:decimal-add("1.1","2.2")}</decimal-add>

The preceding query generates the following result:

<decimal-add>3.3</decimal-add>

Related Topics

W3C decimal data type description.

W3C numeric-add operator description.

op: float-add

Add $float-var1 to $float-var2. The + operator invokes the float-add operator.

Signatures

op:float-add (xs: float $float-var1, xs:float $float-var2) —> xs:float

Table 13-2 Arguments
Data Type
Argument
Description
xs:float
$float-var1
Represents a 32 bit floating point number, for example: 1.1.
xs:float
$float-var2
Represents a 32 bit floating point number, for example: 1.1.

Returns

Returns the float value of adding $float-var1 to $float-var2.

Examples
Simple

Invoking float-add("1.0","2.0") returns the floating point value: 3.0 as shown in the following example query:

<float-add>{op:float-add("1.0","2.0")}</float-add>

The preceding query generates the following result:

<float-add>3.0</float-add>

Related Topics

W3C float data type description.

W3C numeric-add operator description.

op: double-add

Add $double-var1 to $double-var2. The + operator invokes the double-add operator.

Signatures

op:double-add(xs: double $double-var1, xs:double $double-var2) —> xs:double

Table 13-3 Arguments
Data Type
Argument
Description
xs:double
$double-var1
Represents a double precision (64 bit) floating point number, for example: 1.1.
xs:double
$double-var2
Represents a double precision (64 bit) floating point number, for example: 1.1.

Returns

Returns the double value of adding $double-var1 to $double-var2.

Examples
Simple

Invoking double-add("1.0","2.0") returns the double precision floating point value: 3.0 as shown in the following example query:

<double-add>{op:double-add("1.0","2.0")}</double-add>

The preceding query generates the following result:

<double-add>3.0</double-add>

Related Topics

W3C double data type description.

W3C numeric-add operator description.

op: decimal-subtract

Subtracts $decimal-var2 from $decimal-var1. The - operator invokes the decimal-subtract operator.

Signatures

op: decimal-subtract(xs: decimal $decimal-var1, xs:decimal $decimal-var2) —> xs:decimal

Table 13-4 Arguments
Data Type
Argument
Description
xs:decimal
$decimal-var1
Represents a decimal number, for example: 1.1.
xs:decimal
$decimal-var2
Represents a decimal number, for example: 1.1.

Returns

Returns the decimal value of subtracting $decimal-var2 from $decimal-var1.

Examples
Simple

Invoking decimal-subtract("2.2","1.1") returns the decimal value 1.1 as shown in the following example query:

<decimal-subtract>{op:decimal-subtract("2.2","1.1")}</decimal-subtract>

The preceding query generates the following result:

<decimal-subtract>1.1</decimal-subtract>

Related Topics

W3C decimal data type description.

W3C numeric-subtract operator description.

op: float-subtract

Subtracts $float-var2 from $float-var1. The - operator invokes the float-subtract operator.

Signatures

op:float-subtract(xs: float $float-var1, xs:float $float-var2) —> xs:float

Table 13-5 Arguments
Data Type
Argument
Description
xs:float
$float-var1
Represents a 32 bit floating point number, for example: 1.1.
xs:float
$float-var2
Represents a 32 bit floating point number, for example: 1.1.

Returns

Returns the floating point value of subtracting $float-var2 from $float-var1.

Examples
Simple

Invoking float-subtract("2.2","1.1") returns the floating point value: 1.1 as shown in the following example query:

<float-subtract>{op:float-subtract("2.2","1.1")}</float-subtract>

The preceding query generates the following result:

<float-subtract>1.1</float-subtract>

Related Topics

W3C float data type description.

W3C numeric-subtract operator description.

op: double-subtract

Subtracts $double-var2 from $double-var1. The - operator invokes the double-subtract operator.

Signatures

op:double-subtract(op: double $double-var1, op:double $double-var2) —> xs:double

Table 13-6 Arguments
Data Type
Argument
Description
xs:double
$double-var1
Represents a double precision (64 bit) floating point number, for example: 1.1.
xs:double
$double-var2
Represents a double precision (64 bit) floating point number, for example: 1.1.

Returns

Returns the double precision (64 bit) floating point value of subtracting $double-var2 from $double-var1.

Examples
Simple

Invoking double-subtract("2.2","1.1") returns the double precision (64 bit) floating point value: 1.1 as shown in the following example query:

<double-subtract>{op:double-subtract("2.2","1.1")}</double-subtract>

The preceding query generates the following result:

<double-subtract>1.1</double-subtract>

Related Topics

W3C double data type description.

W3C numeric-subtract operator description.

op: decimal-multiply

Multiplies $decimal-var1 by $decimal-var2. The * operator invokes the decimal-multiply operator.

Signatures

op:decimal-multiply(xs: decimal $decimal-var1,xs:decimal $decimal-var2) —> xs:decimal

Table 13-7 Arguments
Data Type
Argument
Description
xs:decimal
$decimal-var1
Represents a decimal number, for example: 1.1.
xs:decimal
$decimal-var2
Represents a decimal number, for example: 1.1.

Returns

Returns the decimal value of multiplying $decimal-var1 by $decimal-var2.

Examples
Simple

Invoking decimal-multiply("2.0","1.0") returns the decimal value: 2 as shown in the following example query:

<decimal-multiply>{op:decimal-multiply("2.0","1.0")}</decimal-multiply>

The preceding query generates the following result:

<decimal-multiply>2</decimal-multiply>

Related Topics

W3C decimal data type description.

W3C numeric-multiply operator description.

op: float-multiply

Multiplies $float-var1 by $float-var2. The * operator invokes the float-multiply operator.

Signatures

op: float-multiply(op: float $float-var1, xs:float $float-var2) —> xs:float

Table 13-8 Arguments
Data Type
Argument
Description
xs:float
$float-var1
Represents a 32 bit floating point number, for example: 1.1.
xs:float
$float-var2
Represents a 32 bit floating point number, for example: 1.1.

Returns

Returns the 32 bit floating point value of multiplying $float-var1 by $float-var2.

Examples
Simple

Invoking float-multiply("2.0","3.0") returns the floating point value: 6.0 as shown in the following example query:

<float-multiply>{op:float-multiply("2.0","3.0")}</float-multiply>

The preceding query generates the following result:

<float-multiply>6.0</float-multiply>

Related Topics

W3C float data type description.

W3C numeric-multiply operator description.

op: double-multiply

Multiplies $double-var1 by $double-var2. The * operator invokes the double-multiply operator.

Signatures

op:double-multiply (xs: double $double-var1, xs:double $double-var2) —> xs:double

Table 13-9 Arguments
Data Type
Argument
Description
xs:double
$double-var1
Represents a double precision (64 bit) floating point number, for example: 1.1.
xs:double
$double-var2
Represents a double precision (64 bit) floating point number, for example: 1.1.

Returns

Returns the double precision (64 bit) floating point value of multiplying $double-var1 by $double-var2.

Examples
Simple

Invoking double-multiply("2.0","3.0") returns the double precision floating point value: 6.0 as shown in the following example query:

<double-multiply>{op:double-multiply("2.0","3.0")}</double-multiply>

The preceding query generates the following result:

<double-multiply>6.0</double-multiply>

Related Topics

W3C double data type description.

W3C numeric-multiply operator description.

op: decimal-divide

Divides $decimal-var1 by $decimal-var2. The div operator invokes the decimal-divide operator.

If the value of $decimal-var2 is equal to zero, the TransformException exception is raised with the RT_DIV_ZERO fault code. The following error message is displayed in the mapper:

Error occurred while executing XQuery: division by zero

Signatures

op: decimal-divide(xs: decimal $decimal-var1, xs: $decimal-var2) —> xs:decimal

Table 13-10 Arguments
Data Type
Argument
Description
xs:decimal
$decimal-var1
Represents a decimal number, for example: 1.1.
xs:decimal
$decimal-var2
Represents a decimal number, for example: 1.1.

Returns

Returns the decimal value of dividing $decimal-var1 by $decimal-var2.

Examples
Simple

Invoking decimal-divide("2.2","1.1") returns the decimal value 2 as shown in the following example query:

<decimal-divide>{op:decimal-divide("2.2","1.1")}</decimal-divide>

The preceding query generates the following result:

<decimal-divide>2.0</decimal-divide>

Error—Divide by Zero

Invoking decimal-divide("2.2","0") throws the TransformException exception with the RT_DIV_ZERO fault code as shown in the following example query:

<decimal-divide>{op:decimal-divide("2.2","0")}</decimal-divide>

The following error message is displayed in the mapper:

Error occurred while executing XQuery: division by zero

Related Topics

W3C decimal data type description.

W3C numeric-divide operator description.

op: float-divide

Divides $float-var1 by $float-var2. The div operator invokes the float-divide operator .

If the value of $float-var2 is equal to zero, the value of Infinity is returned. To learn more see Divide by Zero.

Signatures

op:float-divide(xs: float $float-var1, xs:float $float-var2) —>xs:float

Table 13-11 Arguments
Data Type
Argument
Description
xs:float
$float-var1
Represents a 32 bit floating point number, for example: 1.1.
xs:float
$float-var2
Represents a 32 bit floating point number, for example: 1.1.

Returns

Returns the floating point value of dividing $float-var1 by $float-var2.

Examples
Simple

Invoking float-divide("4.4","2.2") returns the floating point value of 2.0 as shown in the following example query:

<float-divide>{op:float-divide("4.4","2.2")}</float-divide>

The preceding query generates the following result:

<float-divide>2.0</float-divide>

Divide by Zero

Invoking float-divide("2.2","0") returns the Infinity value as shown in the following example query:

<float-divide>{op:float-divide("2.2","0")}</float-divide>

The preceding query generates the following result:

<float-divide>Infinity</float-divide>

To learn more see the IEEE Standard for Binary Floating-Point Arthimetic.

Related Topics

W3C float data type description.

W3C numeric-divide operator description.

IEEE Standard for Binary Floating-Point Arthimetic.

op: double-divide

Divides $double-var1 by $double-var2. The div operator invokes the double-divide operator.

If the value of $double-var2 is equal to zero, the value of Infinity is returned. To learn more see Divide by Zero.

Signatures

op:double-divide(xs: double $double-var1, xs:double $double-var2) —> xs:double

Table 13-12 Arguments
Data Type
Argument
Description
xs:double
$double-var1
Represents a double precision (64 bit) floating point number, for example: 1.1.
xs:double
$double-var2
Represents a double precision (64 bit) floating point number, for example: 1.1.

Returns

Returns the double precision floating point value of dividing $double-var1 by $double-var2.

Examples
Simple

Invoking double-divide("4.4","2.2") returns the double precision floating point value of 2.0 as shown in the following example query:

<double-divide>{op:double-divide("4.4","2.2")}</double-divide>

The preceding query generates the following result:

<double-divide>2.0</double-divide>

Divide by Zero

Invoking double-divide("2.2","0")returns the Infinity value as shown in the following example query:

<double-divide>{op:double-divide("2.2","0")}</double-divide>

The preceding query generates the following result:

<double-divide>Infinity</double-divide>

To learn more see the IEEE Standard for Binary Floating-Point Arthimetic.

Related Topics

W3C double data type description.

W3C numeric-divide operator description.

IEEE Standard for Binary Floating-Point Arthimetic.

op: numeric-integer-divide

Divides $integer-var1 by $integer-var2 and returns the resulting integer. If $integer-var2 is not divided evenly by $integer-var1, the remainder is dropped—no rounding occurs. The idiv operator is invoked by the numeric-integer-divide operator.

If the value of $decimal-var2 is equal to zero, the TransformException exception is raised with the RT_DIV_ZERO fault code. The following error message is displayed in the mapper:

Error occurred while executing XQuery: division by zero

Signatures

op:numeric-integer-divide(xs: integer $integer-var1, xs:integer $double-var2) —> xs:integer

Table 13-13 Arguments
Data Type
Argument
Description
xs:integer
$integer-var1
Represents a integer number, for example: 1.
xs:integer
$integer-var2
Represents a integer number, for example: 1.

Returns

Returns the integer result of dividing $integer-var1 by $integer-var2. If $integer-var2 is not divided evenly by $integer-var1, the remainder is dropped—no rounding occurs.

Examples
No Remainder

Invoking op:numeric-integer-divide("4","2") returns the integer: 2 as shown in the following example query:

<numeric-integer-divide>{

op:numeric-integer-divide("4","2")

}</numeric-integer-divide>

The preceding query generates the following result:

<numeric-integer-divide>2</numeric-integer-divide>

Note: The integer: 4 is divided eventually by the integer: 2 with no remainder.
Throw Away Remainder

Invoking op:numeric-integer-divide("5","2") returns the integer: 2 as shown in the following example query:

<numeric-integer-divide>{

op:numeric-integer-divide("5","2")

}</numeric-integer-divide>

The preceding query generates the following result:

<numeric-integer-divide>2</numeric-integer-divide>

Note: The remainder is discarded.
Error—Divide by Zero

Invoking op:numeric-integer-divide("2","0") throws the TransformException exception with the RT_DIV_ZERO fault code as shown in the following example query:

<numeric-integer-divide>{

op:numeric-integer-divide("2","0")

}</numeric-integer-divide>

The following error message is displayed in the mapper:

Error occurred while executing XQuery: division by zero

Related Topics

W3C integer data type description.

W3C numeric-integer-divide operator description.

op: decimal-mod

Return the remainder of dividing $decimal-var1 by $decimal-var2. The mod operator invokes the decimal-mod operator.

If the value of $decimal-var2 is equal to zero, the TransformException exception is raised with the RT_DIV_ZERO fault code. The following error message is displayed in the mapper:

Error occurred while executing XQuery: division by zero

Signatures

op:decimal-mod(xs: decimal $decimal-var1, xs:decimal $decimal-var2) —>xs:decimal

Table 13-14 Arguments
Data Type
Argument
Description
xs:decimal
$decimal-var1
Represents a decimal number, for example: 1.1.
xs:decimal
$decimal-var2
Represents a decimal number, for example: 1.1.

Returns

Returns the remainder of dividing $decimal-var1 by $decimal-var2.

Examples
Simple

Invoking decimal-mod("2.1","2.0") returns the decimal value .1 because 2.1 divided by 2.0 results in 1 with the remainder: .1. The remainder: .1 is returned as shown in the following example query:

<decimal-mod>{op:decimal-mod("2.1","2.0")}</decimal-mod>

The preceding query generates the following result:

<decimal-mod>0.1</decimal-mod>

Error—Divide by Zero

Invoking decimal-mod("2.2","0")throws the TransformException exception with the RT_DIV_ZERO fault code as shown in the following example query:

<decimal-mod>{op:decimal-mod("2.2","0")}</decimal-mod>

The following error message is displayed in the mapper:

Error occurred while executing XQuery: division by zero

Related Topics

W3C decimal data type description.

W3C numeric-mod operator description.

op: float-mod

Return the remainder of dividing $float-var1 by $float-var2. The mod operator invokes the float-mod operator.

To learn more about using this operator with NaN, positive infinity, or negative infinity operands, see the W3C numeric-mod operator description.

Signatures

op: float-mod(xs: float $float-var1, xs:float $float-var2) —> xs:float

Table 13-15 Arguments
Data Type
Argument
Description
xs:float
$float-var1
Represents a 32 bit floating point number, for example: 1.1.
xs:float
$float-var2
Represents a 32 bit floating point number, for example: 1.1.

Returns

Returns the remainder of dividing $float-var1 by $float-var2.

Examples
Simple

Invoking float-mod("1.25","1.0") returns the floating point value: .25 because 1.25 divided by 1.0 results in 1 with the remainder: .25. The remainder: .25 is returned as shown in the following example query:

<float-mod>{op:float-mod("1.25","1.0")}</float-mod>

The preceding query generates the following result:

<float-mod>0.25</float-mod>

Divide by Zero

Invoking float-mod("2.2","0")returns a NaN (Not a Number) value as shown in the following example query:

<float-mod>{op:float-mod("2.2","0")}</float-mod>

The preceding query generates the following result:

<float-mod>NaN</float-mod>

Related Topics

W3C float data type description.

W3C numeric-mod operator description.

op: double-mod

Return the remainder of dividing $double-var1 by $double-var2. The mod operator invokes the double-mod operator.

To learn more about using this operator with NaN, positive infinity, or negative infinity operands, see the W3C numeric-mod operator description.

Signatures

op: double-mod(xs: double $double-var1, xs:double $double-var2) —> xs:double

Table 13-16 Arguments
Data Type
Argument
Description
xs:double
$double-var1
Represents a double precision (64 bit) floating point number, for example: 1.1.
xs:double
$double-var2
Represents a double precision (64 bit) floating point number, for example: 1.1.

Returns

Returns the remainder of dividing $double-var1 by $double-var2.

Examples
Simple

Invoking double-mod("1.25","1.0") returns the double precision (64 bit) floating point value: .25 because 1.25 divided by 1.0 results in 1 with the remainder: .25. The remainder: .25 is returned as shown in the following example query:

<double-mod>{op:double-mod("1.25","1.0")}</double-mod>

The preceding query generates the following result:

<double-mod>0.25</double-mod>

Divide by Zero

Invoking double-mod("2.2","0")returns a NaN value as shown in the following example query:

<double-mod>{op:double-mod("2.2","0")}</double-mod>

The preceding query generates the following result:

<double-mod>NaN</double-mod>

Related Topics

W3C double data type description.

W3C numeric-mod operator description.


  Back to Top       Previous  Next