![]() ![]() ![]() ![]() ![]() ![]() |
This chapter provides descriptions of the XQuery duration functions 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 functions. 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 functions available from the mapper functionality:
Converts $string-var
(a string in the yearMonthDuration format) to the
yearMonthDuration data type.
If $string-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xf:
YearMonthDuration(
xs:
string $string-var) —> xf:
yearMonthDuration
Returns a duration of time as a yearMonthDuration value.
Invoking yearMonthDuration("P1Y2M")
returns a yearMonthDuration value corresponding to 1 year and 2 months, as shown in the following example query:
let $mydur := xf:yearMonthDuration("P1Y2M")
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
The preceding query, generates the following XML result:
Invoking yearMonthDuration("P9Y")
returns a yearMonthDuration value corresponding to 9 years, as shown in the following example query:
let $mydur := xf:yearMonthDuration("P9Y")
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
The preceding query, generates the following XML result:
Invoking yearMonthDuration("-P10M")
returns a yearMonthDuration value corresponding to a negative 10 months, as shown in the following example query:
let $mydur := xf:yearMonthDuration("-P10M")
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
The preceding query, generates the following XML result:
W3C yearMonthDuration data type description.
Converts $string-var
(a string in the day TimeDuration format) to the
dayTimeDuration data type.
If $string-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xs:
dayTimeDuration(
xs: string $string-var) —>xf:
dayTimeDuration
|
|||||
|
|||||
Returns a duration of time as a dayTimeDuration value.
Invoking dayTimeDuration("P4DT9H8M20S")
returns a dayTimeDuration value corresponding to 4 days, 9 hours, 8 minutes, and 20 seconds, as shown in the following example query:
let $mydur := xf:dayTimeDuration("P4DT9H8M20S")
<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>
<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>
<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>
<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>
The preceding query, generates the following XML result:
Invoking dayTimeDuration("PT2H20S")
returns a dayTimeDuration value corresponding to 2 hours and 20 seconds, as shown in the following example query:
let $mydur := xf:dayTimeDuration("PT2H20S")
<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>
<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>
<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>
<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>
The preceding query, generates the following XML result:
Invoking dayTimeDuration("-P10D")
returns a dayTimeDuration value corresponding to negative 10 days, as shown in the following example query:
let $mydur := xf:dayTimeDuration("-P10D")
<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>
<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>
<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>
<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>
The preceding query, generates the following XML result:
W3C dayTimeDuration data type description.
Extracts the number of years from the years component of $yearMonthDuration-var.
If the value of $yearMonthDuration-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xf:
get-years-from-yearMonthDuration(xf:
yearMonthDuration ?$yearMonthDuration-var)
—> xs: integer?
Returns the number of year as an integer from years component of $yearMonthDuration-var
.
<years>{xf:get-years-from-yearMonthDuration(xf:yearMonthDuration("P2Y13M"))}</years>
The preceding query generates the following result:
Note: | Even though 13 months is specified in the month component (13M) of the yearMonthDuration creation string (adding up to an additional year), only 2 years is returned as originally specified by the years component (2Y). |
<years>{xf:get-years-from-yearMonthDuration(xf:yearMonthDuration("-P5Y"))}</years>
The preceding query generates the following result:
<years>{xf:get-years-from-yearMonthDuration(xf:yearMonthDuration("P10M"))}</years>
The preceding query generates the following result:
W3C get-years-from-yearMonthDuration function description.
W3C yearMonthDuration data type description.
Extracts the number of months from the months component of $yearMonthDuration-var.
If the value of $yearMonthDuration-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xf:
get-months-from-yearMonthDuration(xf:
yearMonthDuration? $yearMonthDuration-var)
—> xs: integer?
Returns the number of months as an integer from months component of $yearMonthDuration-var
.
<months>{xf:get-months-from-yearMonthDuration(xf:yearMonthDuration("P2Y10M"))}</months>
The preceding query generates the following result:
<months>{xf:get-months-from-yearMonthDuration(xf:yearMonthDuration("-P5M"))}</months>
The preceding query generates the following result:
W3C get-months-from-yearMonthDuration function description.
W3C yearMonthDurationdata type description.
Extracts the number of days from the days component of $dayTimeDuration-var
.
If the value of $dayTimeDuration-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xf:
get-days-from-dayTimeDuration(xf:
dayTimeDuration?$dayTimeDuration-var)
—> xs: integer?
Returns the number of days as an integer from days component of $dayTimeDuration-var
.
<days>{xf:get-days-from-dayTimeDuration(xf:dayTimeDuration("P7DT25H8M20S"))}</days>
The preceding query generates the following result:
Note: | Even though 25 hours is specified in the hours component (25H) of the dayTimeDuration creation string (adding up to an additional day), only 7 days are returned as originally specified by the days component (7D). |
<days>{xf:get-days-from-dayTimeDuration(xf:dayTimeDuration("-PT4D"))}</days>
The preceding query generates the following result:
<days>{xf:get-days-from-dayTimeDuration(xf:dayTimeDuration("PT2H20S"))}</days>
The preceding query generates the following result:
W3C get-days-from-dayTimeDuration function description.
W3C dayTimeDuration data type description.
Extracts the number of hours from the hours component of $dayTimeDuration-var
.
If the value of $dayTimeDuration-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xf:
get-hours-from-dayTimeDuration(xf:
dayTimeDuration?$dayTimeDuration-var)
—> xs: integer?
Returns the number as hours as an integer from hours component of $dayTimeDuration-var
.
<hours>{xf:get-hours-from-dayTimeDuration(xf:dayTimeDuration("P7DT9H65M20S"))}</hours>
The preceding query generates the following result:
Note: | Even though 65 minutes is specified in the minutes component (65M) of the dayTimeDuration creation string (adding up to an additional hour), only 9 hours are returned as originally specified by the hours component (9H). |
<hours>{xf:get-hours-from-dayTimeDuration(xf:dayTimeDuration("-PT3H"))}</hours>
The preceding query generates the following result:
<hours>{xf:get-hours-from-dayTimeDuration(xf:dayTimeDuration("P2DT20S"))}</hours>
The preceding query generates the following result:
W3C get-hours-from-dayTimeDuration function description.
W3C dayTimeDuration data type description.
Extracts the number of minutes from the minutes component of $dayTimeDuration-var
.
If the value of $dayTimeDuration-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xf:
get-minutes-from-dayTimeDuration
(xf:
dayTimeDuration?$dayTimeDuration-var
) —> xs: integer?
Returns the number as minutes as an integer from minutes component of $dayTimeDuration-var
.
<minutes>{xf:get-minutes-from-dayTimeDuration(xf:dayTimeDuration("P7DT9H12M65S"))}</minutes>
The preceding query generates the following result:
Note: | Even though 65 seconds is specified in the seconds component (65S) of the dayTimeDuration creation string (adding up to an additional minute), only 12 minutes are returned as originally specified by the minutes component (12M). |
<minutes>{xf:get-minutes-from-dayTimeDuration(xf:dayTimeDuration("-PT3M"))}</minutes>
The preceding query generates the following result:
<minutes>{xf:get-minutes-from-dayTimeDuration(xf:dayTimeDuration("P2DT20S"))}</minutes>
The preceding query generates the following result:
W3C get-minutes-from-dayTimeDuration function description.
W3C dayTimeDuration data type description.
Extracts the number of seconds from the seconds component of $dayTimeDuration-var
.
If the value of $dayTimeDuration-var
is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items ()
, which is similar to null in SQL.
xf:
get-seconds-from-dayTimeDuration(xf:
dayTimeDuration?$dayTimeDuration-var) —> xf:
decimal?
Returns the number as seconds as an decimal from seconds component of $dayTimeDuration-var
.
<seconds>{xf:get-seconds-from-dayTimeDuration(xf:dayTimeDuration("P7DT9H12M14S"))}</seconds>
The preceding query generates the following result:
<seconds>{xf:get-seconds-from-dayTimeDuration(xf:dayTimeDuration("-PT7S"))}</seconds>
The preceding query generates the following result:
<seconds>{xf:get-seconds-from-dayTimeDuration(xf:dayTimeDuration("P2DT6M"))}</seconds>
The preceding query generates the following result:
W3C get-seconds-from-dayTimeDuration function description.
W3C dayTimeDuration data type description.
Computes the time difference between $dateTime-var1
and $dateTime-var2
and returns it as a
yearMonthDuration value.
If the value of $date-var1
follows in time the value of $date-var2
, then the returned value is a negative duration. (The date specified in $dateTime-var1 comes before the date specified in $dateTime-var2
.) To learn more, see the following Negative Difference example.
The time difference between the values of two dateTime arguments could include years, months, minutes, and seconds but a yearMonthDuration value can only contain years and months, so the time difference is rounded to nearest month. If the time difference between the two dateTime arguments is greater than or equal to 15.5 days (15 days and 12 hours), the month duration is rounded up. To learn more, see the following Round Up and Not Enough to Round Up examples.
If the value of $date-var1
or $date-var2
is the empty sequence, the following error is displayed:
Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function subtract-dates invocation: expected type [date@http://www.w3.org/2001/XMLSchema], given type empty
xf:
get-yearMonthDuration-from-dateTimes(
xs: dateTime $dateTime-var1, xs: dateTime $dateTime-var2) —>xf: yearMonthDuration
Returns the time difference between $dateTime-var1
and $dateTime-var2
as a yearMonthDuration value.
Returns a negative yearMonthDuration value if $dateTime-var1
follows in time $dateTime-var2
. (The date specified in $dateTime-var1 comes before the date specified in $dateTime-var2
.) To learn more, see the following Negative Difference example.
The following example query returns a positive years and months duration because the date specified in $datetime-var1
comes after the date specified in $datetime-var2
:
let $dateTime-var1 := xs:dateTime("2002-12-26T00:00:01")
let $dateTime-var2 := xs:dateTime("2001-11-26T00:00:01")
let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
The preceding query generates the following result:
The following example query returns a negative years and month duration because the date specified in $dateTime-var1
comes before the date specified in $dateTime-var2
:
let $dateTime-var1 := xs:dateTime("2001-11-26T00:00:01")
let $dateTime-var2 := xs:dateTime("2002-12-26T00:00:01")
let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
The preceding query generates the following result:
The following example query returns a 1 month
yearMonthDuration because there are 15.5 days (15 days and 12 hours) between $dateTime-var1
and $dateTime-var2
:
let $dateTime-var1 := xs:dateTime("2002-11-16T12:00:00")
let $dateTime-var2 := xs:dateTime("2002-11-01T00:00:00")
let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
The preceding query generates the following result:
The following example query returns a 0 months
yearMonthDuration because there are only 15 days, 11 hours, 59 minutes, and 59 seconds (1 second from 15.5 days) between $dateTime-var1
and $dateTime-var2
:
let $dateTime-var1 := xs:dateTime("2002-11-16T11:59:59")
let $dateTime-var2 := xs:dateTime("2002-11-01T00:00:00")
let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
The preceding query generates the following result:
W3C get-yearMonthDuration-from-dayTimes function description.
W3C yearMonthDuration data type description.
W3C dateTime data type description
Computes the time difference between $dateTime-var1
and $dateTime-var2
and returns it as a
dayTimeDuration value.
If the value of $date-var1
follows in time the value of $date-var2
, then the returned value is a negative duration.
If the value of $date-var1
or $date-var2
is the empty sequence, the following error is displayed:
Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function subtract-dates invocation: expected type [date@http://www.w3.org/2001/XMLSchema], given type empty
xf:
get-dayTimeDuration-from-dateTimes(
xs:
dateTime $dateTime-var1
, xs: dateTime $dateTime-var2) —> xf: dayTimeDuration
Returns the time difference between $dateTime-var1
and $dateTime-var2
as a dayTimeDuration value.
Returns a negative dayTimeDuration value if $dateTime-var1
follows in time $dateTime-var2
. (The date specified in $dateTime-var1 comes before the date specified in $dateTime-var2
.) To learn more, see the following Negative Difference example.
The following example query returns a positive days, hours, minutes, and seconds duration because the date specified in $datetime-var1 comes after the date specified in $datetime-var2
:
let $dateTime-var1 := xs:dateTime("2002-12-26T01:01:01")
let $dateTime-var2 := xs:dateTime("2001-11-26T00:00:00")
let $mydur := xf:get-dayTimeDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>
<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>
<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>
<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>
The preceding query generates the following result:
The following example query returns a negative days, hours, minutes, and seconds duration because the date specified in $dateTime-var1
comes before the date specified in $dateTime-var2
:
let $dateTime-var1 := xs:dateTime("2001-11-26T00:00:00")
let $dateTime-var2 := xs:dateTime("2002-12-26T01:01:01")
let $mydur := xf:get-dayTimeDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>
<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>
<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>
<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>
The preceding query generates the following result:
W3C get-dayTimeDuration-from-dateTimes function description.
W3C dayTimeDuration data type description.
W3C dateTime data type description.
![]() ![]() ![]() |