// math reference

SQL LOG10 function

Returns the base-10 logarithm: LOG10(100) is 2 and LOG10(0.001) is -3.

Categoria
Math
Returns
float / double
In this category
22 of 82

Sintaxe

LOG10(number)

Suporte a mecanismos

MotorSupportNotas
SQL Server Sim Supported under this name.
PostgreSQL Sim log10(x) since PostgreSQL 12; one-argument log(x) is also base 10
MySQL Sim Supported under this name.
SQLite Sim log10(X) and log(X) are both base 10 on 3.35+
Oracle Different name or syntax No LOG10; write LOG(10, x)

Exemplos

SQL Server

SELECT LOG10(1000) AS three;  -- 3

PostgreSQL

SELECT LOG10(1000) AS a, LOG(1000) AS b;  -- 3, 3: one-argument log is base 10

MySQL

SELECT ORDER_SIZE, LOG10(ORDER_SIZE) AS digits
FROM shipments;

Bom saber

  • LOG10(1000) is 3 but LOG10(999) is 2.9995...; floats, so round when checking digit counts.
  • Domain is positive only: LOG10(0) and LOG10(-1) return NULL on MySQL and SQLite and raise an error on SQL Server and PostgreSQL, as Oracle's LOG(10, 0) does.
  • PostgreSQL accepts both log10(x) and log(x) for base 10. Its two-argument log(base, x) takes the base first, the reverse of SQL Server's LOG(x, base).

Questions about LOG10

Does PostgreSQL have LOG10?

Yes, since PostgreSQL 12, and one-argument log(x) is base 10 as well. For two-argument logs, PostgreSQL takes the base first: log(10, 1000) is 3.

What is the Oracle equivalent of LOG10?

LOG(10, x): Oracle's LOG takes the base as the first argument, and there is no one-argument form.

Why is LOG10(0) an error or NULL?

The base-10 log of zero is undefined. MySQL and SQLite return NULL; SQL Server, PostgreSQL and Oracle (LOG(10, 0)) raise an error. Filter x > 0 first.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.