MySQL: LOG Function
This MySQL tutorial explains how to use the MySQL LOG function with syntax and examples.
Description
The MySQL 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 MySQL 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
Applies To
The LOG function can be used in the following versions of MySQL:
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let's look at some MySQL LOG function examples and explore how to use the LOG function in MySQL.
For example, let's look at some examples of the LOG function when one parameter is provided:
mysql> SELECT LOG(1); Result: 0 mysql> SELECT LOG(2); Result: 0.6931471805599453 mysql> SELECT LOG(2.5); Result: 0.9162907318741551 mysql> SELECT LOG(0); Result: NULL
Now let's look at some examples of the LOG function when two parameters are provided:
mysql> SELECT LOG(2, 1); Result: 0 mysql> SELECT LOG(3, 4); Result: 1.2618595071429148 mysql> SELECT LOG(2, 0); Result: NULL mysql> SELECT LOG(1, 4); Result: NULL
Advertisements