Numeric Scalar Functions

The list of official SQL2003 numeric functions is rather small, and the different platforms provide supplementary mathematical and statistical functions. MySQL directly supports many of these functions. The other database platforms offer the same capabilities of numeric scalar functions through their own internally defined functions, but they do not share the same name as those declared by the SQL standard. The supported numeric functions and syntax are listed in Table 4-4.

Table 4-4. SQL2003 numeric functions

Function

Usage

ABS

Returns the absolute value of a number.

MOD

Returns the remainder of one number divided into another.

BIT_LENGTH

Returns an integer value representing the number of bits in another value.

CEIL or CEILING

Rounds a noninteger value upwards to the next greatest integer. Returns an integer value unchanged.

CHAR_LENGTH

Returns an integer value representing the number of characters in a string expression.

EXP

Raises a value to the power of the mathematical constant known as e.

EXTRACT

Allows the datepart to be extracted (YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, TIMEZONE_HOUR, or TIMEZONE_MINUTE) from a temporal expression.

FLOOR

Rounds a noninteger value downwards to the next least integer. Returns an integer value unchanged.

LN

Returns the natural logarithm of a number.

OCTET_LENGTH

Returns an integer value representing the number of octets in another value. This value is the same as BIT_LENGTH/8 ...

Get SQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.