totn MariaDB Functions

MariaDB: LOG Function

This MariaDB tutorial explains how to use the MariaDB LOG function with syntax and examples.

Description

The MariaDB LOG function returns either the natural logarithm of a number if called with one parameter, or the logarithm of a number to a specified base if called with two parameters.

Syntax

The syntax for the LOG function in MariaDB is:

LOG( number )

OR

LOG( base, number )

Parameters or Arguments

number
The number to take the natural logarithm of. Must be greater than 0.
base
The base the natural logarithm is to be calculated with. Must be greater than 1.

Note

  • The LOG function will return NULL, if number is less than or equal to 0.
  • The LOG function will return NULL, if base is less than or equal to 1.
  • See also the LN and EXP functions.

Applies To

The LOG function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB LOG function examples and explore how to use the LOG function in MariaDB.

For example, let's look at some examples of the LOG function when one parameter is provided:

SELECT LOG(2);
Result: 0.6931471805599453

SELECT LOG(2.1);
Result: 0.7419373447293773

SELECT LOG(-3);
Result: NULL

SELECT LOG(0);
Result: NULL

Now let's look at some examples of the LOG function when two parameters are provided:

SELECT LOG(2, 5);
Result: 2.321928094887362

SELECT LOG(3, 4);
Result: 1.2618595071429148

SELECT LOG(3, 0);
Result: NULL

SELECT LOG(1, 4);
Result: NULL