December 12th, 2008

LN (natural logarithm)

The LN function returns the natural logarithm of a number, which is the power to which you would need to raise the constant e (approximately 2.718281828…) in order to get the result.
Format:                        LN(expression)

Example:           SELECT LN(2.718281) FROM TABLEA;

Result:

                   

> DB2, Oracle, and PostgreSQL support the LN function.

> DB2 and PostgreSQL also support LOG as a synonym.

> MySQL and SQL Server only support the non-standard LOG function.

> Use the EXP function to reverse the process.

December 11th, 2008

FLOOR (round downward)

he FLOOR function returns the largest integer less than the input value.
Format:                        FLOOR(expression)

Example:           SELECT FLOOR(10.8) FROM TABLEA;

Result:

                   

>DB2, MySQL, Oracle, and SQL Server support FLOOR.

> Access, PostgreSQL, and Sybase don’t support FLOOR.

December 10th, 2008

EXTRACT (part of date/time)

The EXTRACT function extracts parts from a date and gives a datetime value.

Format: EXTRACT(date_part FROM expression)

Date_parts are:
CENTURY ................................. PostgreSQL .................
DAY ............. Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
DAY_HOUR ................... MySQL ...................................
DAY_MINUTE ................. MySQL ...................................
DAY_SECOND ................. MySQL ...................................
DAYOFYEAR .......................................... SQL Server ......
DECADE .................................. PostgreSQL .................
DOW (day of week) ....................... PostgreSQL .................
DOY (day of year) ....................... PostgreSQL .................
EPOCH ................................... PostgreSQL .................
HOUR ............ Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
HOUR_MINUTE ................ MySQL ...................................
HOUR_SECOND ................ MySQL ...................................
MICROSECONDS ........... DB2 ............ PostgreSQL .................
MILLENNIUM .............................. PostgreSQL .................
MILLISECONDS ............................ PostgreSQL SQL Server ......
MINUTE .......... Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
MINUTE_SECOND .............. MySQL ...................................
MONTH ........... Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
MONTHNAME ....... Access .............................................
QUARTER ................................. PostgreSQL SQL Server ......
SECOND .......... Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
TIMEZONE_ABBR .................... Oracle ............................
TIMEZONE_HOUR .................... Oracle PostgreSQL .......... Sybase
TIMEZONE_MINUTE .................. Oracle PostgreSQL .......... Sybase
TIMEZONE_REGION .................. Oracle ............................
WEEK ................... DB2 ..... Oracle PostgreSQL SQL Server ......
WEEKDAY ......... Access ........................... SQL Server ......
WEEKDAYNAME ..... Access .............................................
YEAR ............ Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
YEAR_MONTH ................. MySQL ...................................

Example: SELECT EXTRACT(DAY FROM ’2056-01-11′) FROM TABLEA;

Result:

                   

> A date or time range returns all the values inbetween, such as DAY_SECOND gives DAY, HOUR, MINUTE, SECOND (11 09:15:00).
> MySQL, Oracle, PostgreSQL, and Sybase support EXTRACT.
> Access, and SQL Server do not support EXTRACT. Instead, they use DATEPART(date_part, expression).
Access also supports DATEADD, DATEDIFF, DATESERIAL, DATEVALUE, TIMESERIAL, and TIMEVALUE.
> DB2 does not support EXTRACT. Instead, it uses the date_part name as the functions, such as DAY(expression).
Other DB2 functions include LOCAL_TIME, and LOCAL_TIMESTAMP.
> MySQL also supports NOW().

« Previous PageNext Page »