What is LOG() in SQL?

The LOG() function returns the logarithm of a number to the specific base.

Figure 1 shows the mathematical representation of the LOG() function:

Figure 1: Mathematical representation of the LOG() function

Syntax

LOG(base, number)

Parameter

This function requires two parameters:

  • The base of the logarithma number (which must be greater than one) is an optional parameter.
  • A number whose logarithm is to be calculated, it must be greater than zero.

Return Value

LOG() returns the logarithm of a number to the specific base sent as a parameter.

If the base is omitted, then the LOG() function calculates the natural logarithm of a number, which is the same as the LOG() function with a base of the mathematical constant e.

If the base is less than one, or the number is less than zero, the function will return NULL.

Example

/*example showing how to use LOG(base, number)*/
-- positive number without base
select LOG(10);
-- positive number with base
select LOG(3,3);
-- zero number with base
select LOG(2,0);
-- positive number with base 0
select LOG(0,2);