Numeric Scalar Functions

The list of official ANSI SQL numeric functions is rather small, and the different platforms provide supplementary mathematical and statistical functions. MySQL and PostgreSQL both support many of the ANSI standard 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 names as those declared by the SQL standard. The supported numeric functions and syntax are listed in Table 4-4.

Table 4-4. ANSI SQL numeric functions

Function

Usage

ABS

Returns the absolute value of a number.

BIT_LENGTH

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

CEIL or CEILING

Rounds a noninteger value upward 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 downward to the next least integer. Returns an integer value unchanged.

LN

Returns the natural logarithm of a number.

MOD

Returns the remainder of one number divided into another.

OCTET_LENGTH

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

POSITION

Returns an integer value representing ...

Get SQL in a Nutshell, 3rd 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.