Microsoft SQL Server and Sybase Adaptive Server Oracle Description
Microsoft SQL Server and Sybase Adaptive Server Oracle Description
Table 2-19 Date Functions in Oracle and Microsoft SQL Server and Sybase Adaptive Server
Recommendations:
The above table lists all the Microsoft SQL Server and Sybase Adaptive Server date
manipulation functions. It does not list all the Oracle date functions. There are many more Oracle
date manipulation functions that you can use.
It is recommended that you convert most date manipulation functions to "+" or "-" in Oracle.
Oracle adds the ability to define functions. With this feature you can create Oracle functions that
match the name and functionality of all Microsoft SQL Server and Sybase Adaptive Server
functions. This is a useful feature, where users can call a PL/SQL function from a SQL
statement's SELECT LIST, WHERE clause, ORDER BY clause, and HAVING clause. With the
parallel query option, Oracle executes the PL/SQL function in parallel with the SQL statement.
Hence, users create parallel logic.
In Oracle you can add or substract a number of days from a date. Example:
+,- (plus/minus)
sysdate+5 means systemdate/time plus 5 days
With the greatest function you can select the date/time that is the highest
GREATEST in a range of date/times. Example: greatest (sysdate+4,sysdate,sysdate-5)
= sysdate+4.
With the least function you can select the earliest date/time in a range of
LEAST
date/times. Example: least(sysdate+4,sysdate,sysdate-5) = sysdate-5.
Returns the last_day of a month based on the month the passed date is in.
LAST_DAY
Example: last_day(sysdate) returns the last day of this month.
Returns the number of months between two dates. The number is not
MONTHS_BETWEEN rounded. Example: months_between(sysdate, to_date('01-01-2007','dd-
mm-yyyy')) returns the number of months since jan 1, 2007.
Returns date rounded to the unit specified by the format model. If you
ROUND omit the format, the date is rounded to the nearest day ROUND(, ) SELECT
ROUND(TO_DATE('27-OCT-00'),'YEAR') NEW_YEAR FROM dual;
Format Mask
Rounds or Truncates to
CC or SSC - Century
SYYY, YYYY, YEAR, SYEAR, YYY, YY, or Y - Year (rounds up to next year on July 1)
Q - Quarter (rounds up on the sixteenth day of the second month of the quarter)
MONTH, MON, MM, or RM - Month (rounds up on the sixteenth day, which is not necessarily
the same as the middle of the month)
IW - Same day of the week as the first day of the ISO year
MI - Minute
NEW_TIME - Returns the date/time value, with the time shifted as requested by the specified
time zones