Mapping DATEPART functions: DatePartMapper element
DATEPART takes two arguments: a date part and a timestamp. It returns the part of the timestamp specified by the date part:
Integer datepart( datepart Varchar, value Timestamp )
The DatePartMapper element is used to customize the mappings for the date parts listed in Table 10‑10. The table also shows the default template for each date part.
Table 10‑10 Default templates for mapping date parts with the DATEPART function
Date part
Default template
yyyy (year)
{FN YEAR ($P0)}
q (quarter)
{FN QUARTER ($P0)}
m (month)
{FN MONTH ($P0)}
d (day)
{FN DAYOFMONTH ($P0)}
h (hour)
{FN HOUR ($P0)}
n (minute)
{FN MINUTE ($P0)}
s (second)
{FN SECOND ($P0)}
w (day of week)
{FN DAYOFWEEK ($P0)}
y (day of year)
{FN DAYOFYEAR ($P0)}
Example: Mapping the DATEPART functions
Your database has a different syntax for the DATEPART functions. You define each part using a mapping:
<DatePartMapper>
<FunctionMappings>
<FunctionMapping FunctionName="DATEPART"
DatePart="yyyy">
TO_NUMBER (TO_CHAR ($P0, 'YYYY'))
</FunctionMapping>
<FunctionMapping FunctionName="DATEPART"
DatePart="y">
TO_NUMBER (TO_CHAR ($P0, 'DDD'))
</FunctionMapping>
</FunctionMappings>
</DatePartMapper>