XQuery Reference

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

XQuery Duration Operators Reference

This chapter provides descriptions of the XQuery duration 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 duration operators available from the mapper functionality:

 


op: add-yearMonthDurations

Adds $yearMonthDuration-var1 to $yearMonthDuration-var2.

Signatures

op:add-yearMonthDurations(xf: yearMonthDuration $yearMonthDuration-var1, xf: yearMonthDuration $yearMonthDuration-var2) —> xf: yearMonthDuration

Table 15-1 Arguments
Data Type
Argument
Description
xf:yearMonthDuration
$yearMonthDuration-var1
Contains a time duration that can contain years and months.
xf:yearMonthDuration
$yearMonthDuration-var2
Contains a time duration that can contain years and months.

Returns

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

Examples
Simple

The following example query adds a yearMonthDuration value equal to 1 year and 2 months to a yearMonthDuration value equal to 2 years and 11 months as shown in the following query:

<yearMonthDuration>{

op:add-yearMonthDurations(xf:yearMonthDuration("P1Y2M"), xf:yearMonthDuration("P2Y11M"))

}</yearMonthDuration>

The resulting yearMonthDuration value of 4 years and 1 month is returned as shown in the following result:

<yearMonthDuration>P4Y1M</yearMonthDuration>

Related Topics

W3C add-yearMonthDurations operator description.

W3C yearMonthDuration description.

xf: yearMonthDuration constructor description.

 


op: subtract-yearMonthDurations

Subtracts the value of $yearMonthDuration-var2 from $yearMonthDuration-var1.

Signatures

op:subtract-yearMonthDurations (xf: yearMonthDuration $yearMonthDuration-var1, xf: yearMonthDuration $yearMonthDuration-var2) —> xf:yearMonthDuration

Table 15-2 Arguments
Data Type
Argument
Description
xf:yearMonthDuration
$yearMonthDuration-var1
Contains a time duration that can contain years and months.
xf:yearMonthDuration
$yearMonthDuration-var2
Contains a time duration that can contain years and months.

Returns

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

Examples
Positive

The following example query subtracts a yearMonthDuration value equal to 1 year and 1 month from a yearMonthDuration value equal to 3 years and 3 months as shown in the following query:

<positive>{

op:subtract-yearMonthDurations(xf:yearMonthDuration("P3Y3M"), xf:yearMonthDuration("P1Y1M"))

}</positive>

The resulting positive yearMonthDuration value of 2 years and 2 months is returned as shown in the following result:

<positive>P2Y2M</positive>

Negative

The following example query subtracts a yearMonthDuration value equal to 3 years and 3 months from a yearMonthDuration value equal to 1 year and 1 month as shown in the following query:

<negative>{

op:subtract-yearMonthDurations(xf:yearMonthDuration("P1Y1M"), xf:yearMonthDuration("P3Y3M"))

}</negative>

The resulting negative yearMonthDuration value of 2 years and 2 months is returned as shown in the following result:

<negative>-P2Y2M</negative>

Related Topics

W3C subtract-yearMonthDurations operator description.

W3C yearMonthDuration description.

xf: yearMonthDuration constructor description.

 


op: multiply-yearMonthDuration

Multiplies $yearMonthDuration-var with $decimal-var.

Signatures

op:multiply-yearMonthDuration(xf: yearMonthDuration $yearMonthDuration-var, xs:decimal $decimal-var) —>xf:yearMonthDuration

Table 15-3 Arguments
Data Type
Argument
Description
xf:yearMonthDuration
$yearMonthDuration-var
Contains a time duration that can contain years and months.
xs:decimal
$decimal-var
Contains a decimal value, for example: 1.1.

Returns

Returns the yearMonthDuration value of dividing $yearMonthDuration-var with $decimal-var. The return value is rounded up to the nearest month and year as shown in the following example.

Examples
Round Up

Multiplying the 1 year value of $yearMonthDuration-var by 1.5 results in 1 year and 6 months. Multiplying the 1 month value of $yearMonthDuration-var by 1.5 results in 1.5 months which is rounded up to 2 months. Adding 1 year and 6 months to 2 months results in a yearMonthDuration of 1 year and 8 months as shown in the following example query:

let $yearMonthDuration-var := xf:yearMonthDuration("P1Y1M")

return

let $decimal-var := 1.5

return

let $mydur := op:multiply-yearMonthDuration($yearMonthDuration-var, $decimal-var)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>1</years>

<months>8</months>

</result>

Not Enough to Round Up

Multiplying a 1 month yearMonthDuration by 0.49 results in 0.49 months which is rounded down to zero months as shown in the following example query:

let $yearMonthDuration-var := xf:yearMonthDuration("P1M")

return

let $decimal-var := 0.49

return

let $mydur := op:multiply-yearMonthDuration($yearMonthDuration-var, $decimal-var)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>0</years>

<months>0</months>

</result>

Related Topics

W3C multiply-yearMonthDuration operator description.

W3C yearMonthDuration description.

xf: yearMonthDuration constructor description.

 


op: divide-yearMonthDuration

Divides $yearMonthDuration-var by $decimal-var.

Signatures

op:divide-yearMonthDuration(xf: yearMonthDuration $yearMonthDuration-var, xs:decimal $decimal-var) —>xf:yearMonthDuration

Table 15-4 Arguments
Data Type
Argument
Description
xf:yearMonthDuration
$yearMonthDuration-var
Contains a time duration that can contain years and months.
xs:decimal
$decimal-var
Contains a decimal value, for example: 1.1.

Returns

Returns the yearMonthDuration value of dividing $yearMonthDuration-var by $decimal-var. The return value is rounded up to the nearest year and month as shown in following example.

Examples
Round Up

Dividing the 1 year value of $yearMonthDuration-var by 2.0 results in 6 months. Dividing the 1 month value of $yearMonthDuration-var by 2.0 results in .5 months which is rounded up to 1 month. Adding 6 months to 1 month results in a yearMonthDuration of 7 months as shown in the following example query:

let $yearMonthDuration-var := xf:yearMonthDuration("P1Y1M")

return

let $decimal-var := 2

return

let $mydur := op:divide-yearMonthDuration($yearMonthDuration-var, $decimal-var)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>0</years>

<months>7</months>

</result>

Not Enough to Round Up

Dividing a 1 month yearMonthDuration by 2.04 results in 0.4901... months which is rounded down to zero months as shown in the following example query:

let $yearMonthDuration-var := xf:yearMonthDuration("P1M")

return

let $decimal-var := 2.04

return

let $mydur := op:divide-yearMonthDuration($yearMonthDuration-var, $decimal-var)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>0</years>

<months>0</months>

</result>

Related Topics

W3C divide-yearMonthDuration operator description.

W3C yearMonthDurationdescription.

xf: yearMonthDuration constructor description.

 


op: add-dayTimeDurations

Adds $dayTimeDuration-var1 to $dayTimeDuration-var2.

Signatures

op:add-dayTimeDurations(xf: dayTimeDuration $dayTimeDuration-var1, xf: dayTimeDuration $dayTimeDuration-var2) —>xf:dayTimeDuration

Table 15-5 Arguments
Data Type
Argument
Description
xf:dayTimeDuration
$dayTimeDuration-var1
Contains a time duration that can contain days, hours, minutes, and seconds.
xf:dayTimeDuration
$dayTimeDuration-var2
Contains a time duration that can contain days, hours, minutes, and seconds.

Returns

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

Examples
Simple

The following example query adds a dayTimeDuration value equal to 1 day, 2 hours, 30 minutes, and 5 seconds to a dayTimeDuration value equal to 31 minutes as shown in the following query:

<dayTimeDuration>{

op:add-dayTimeDurations(xf:dayTimeDuration("P1DT2H30M5S"), xf:dayTimeDuration("PT31M"))

}</dayTimeDuration>

The resulting dayTimeDuration value of 1 day, 3 hours, 1 minute, and 5 seconds is returned as shown in the following result:

<dayTimeDuration>P1DT3H1M5S</dayTimeDuration>

Related Topics

W3C add-dayTimeDurations operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.

 


op: subtract-dayTimeDurations

Subtracts the value of $dayTimeDuration-var2 from $dayTimeDuration-var1.

Signatures

op:subtract-dayTimeDurations(xf: dayTimeDuration$dayTimeDuration-var1, xf: dayTimeDuration $dayTimeDuration-var2) —>xf:dayTimeDuration

Table 15-6 Arguments
Data Type
Argument
Description
xf:dayTimeDuration
$dayTimeDuration-var1
Contains a time duration that can contain days, hours, minutes, and seconds
xf:dayTimeDuration
$dayTimeDuration-var2
Contains a time duration that can contain days, hours, minutes, and seconds.

Returns

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

Examples
Positive

The following example query subtracts a dayTimeDuration value equal to 1 day and 1 minute from a dayTimeDuration value equal to 3 days, 3 hours, 3 minutes, and 3 seconds as shown in the following query:

<positive>{

op:subtract-dayTimeDurations(xf:dayTimeDuration("P3DT3H3M3S"), xf:dayTimeDuration("P1DT1M"))

}</positive>

The resulting positive dayTimeDuration value of 2 days, 3 hours, 2 minutes and 3 seconds is returned as shown in the following result:

<positive>P2DT3H2M3S</positive>

Negative

The following example query subtracts a dayTimeDuration value equal to 3 days, 3 hours, 3 minutes, and 3 seconds from a dayTimeDuration value equal to 1 day and 1 minute as shown in the following query:

<negative>{

op:subtract-dayTimeDurations(xf:dayTimeDuration("P1DT1M"), xf:dayTimeDuration("P3DT3H3M3S"))

}</negative>

The resulting negative dayTimeDuration value of 2 years and 2 months is returned as shown in the following result:

<negative>-P2DT3H2M3S</negative>

Related Topics

W3C subtract-dayTimeDurations operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.

 


op: multiply-dayTimeDuration

Multiplies $dayTimeDuration-var with $decimal-var.

Signatures

op:multiply-dayTimeDuration(xf: dayTimeDuration $dayTimeDuration-var,xs: decimal $decimal-var) —> xf:dayTimeDuration

Table 15-7 Arguments
Data Type
Argument
Description
xf:dayTimeDuration
$dayTimeDuration-var
Contains a time duration that can contain days, hours, minutes, and seconds.
xs:decimal
$decimal-var
Contains a decimal value, for example: 1.1.

Returns

Returns the dayTimeDuration value of dividing $dayTimeDuration-var with $decimal-var.

Examples
Simple

Multiplying the 1 day value of $dayTimeDuration-var by 1.5 results in 1 day and 12 hours. Multiplying the 1 hour value of $dayTimeDuration-var by 1.5 results in 1 hour and 30 minutes. Adding 1 day and 12 hours to 1 hour and 30 minutes results in a dayTimeDuration of 1 day, 13 hours, and 30 minutes as shown in the following example query:

<result>{

op:multiply-dayTimeDuration(xf:dayTimeDuration("P1DT1H"), 1.5)

}</result>

The preceding query generates the following result:

<result>P1DT13H30M</result>

Related Topics

W3C multiply-dayTimeDuration operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.

 


op: divide-dayTimeDuration

Divides $dayTimeDuration-var by $decimal-var.

Signatures

op: divide-dayTimeDuration(xf: dayTimeDuration $dayTimeDuration-var, xs:decimal-var $decimal-var) —> xf:dayTimeDuration

Table 15-8 Arguments
Data Type
Argument
Description
xf:dayTimeDuration
$dayTimeDuration-var
Contains a time duration that can contain days, hours, minutes, and seconds.
xs:decimal
$decimal-var
Contains a decimal value, for example: 1.1.

Returns

Returns the dayTimeDuration value of dividing $dayTimeDuration-var by $decimal-var.

Examples
Simple

Dividing the 1 day value of $dayTimeDuration-var by 2.0 results in 12 hours. Dividing the 1 hour value of $dayTimeDuration-var by 2.0 results in 30 minutes. Adding these values together results in a dayTimeDuration of 12 hours and 30 minutes as shown in the following example query:

<result>{

op:divide-dayTimeDuration(xf:dayTimeDuration("P1DT1H"), 2.0)

}</result>

The preceding query generates the following result:

<result>PT12H30M</result>

Related Topics

W3C divide-dayTimeDuration operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.


  Back to Top       Previous  Next