// math reference

SQL EXP function

Returns e raised to the given power: EXP(1) is about 2.71828 and EXP(0) is exactly 1.

類別
Math
Returns
float / double
In this category
19 of 82

語法

EXP(number)

引擎支援

引擎Support備註
SQL Server 是 Supported under this name.
PostgreSQL 是 Supported under this name.
MySQL 是 Supported under this name.
SQLite 是 Requires SQLite 3.35+ with the math functions built in
Oracle 是 Supported under this name.

範例

Any engine

SELECT EXP(0) AS one, EXP(1) AS e;  -- 1, 2.71828...

PostgreSQL

SELECT SUM(amount * EXP(-rate * years)) AS present_value
FROM cash_flows;

SQL Server

SELECT EXP(LOG(10)) AS back_to_ten;  -- 10.000000000000002

小知識

  • Integer input still returns a fraction: EXP(1) is 2.718281828459045 as a double on most engines. PostgreSQL returns numeric for numeric input (exp(1.0)) and Oracle returns NUMBER.
  • EXP(709) is near the top of a double. Past about 709.78, SQL Server, PostgreSQL and MySQL raise an overflow error and SQLite returns Inf. Oracle NUMBER overflows far sooner: EXP(291) raises ORA-01426.
  • EXP and LN undo each other only approximately in floats: on SQL Server EXP(LOG(10)) returns 10.000000000000002.

Questions about EXP

Why does EXP overflow?

EXP(709) is about 8e307, close to the double maximum near 1.8e308. EXP(710) cannot be stored: SQL Server, PostgreSQL and MySQL raise an error, SQLite hands back Inf. Oracle NUMBER caps near 1e126, so EXP(291) already fails there; EXP of a BINARY_DOUBLE returns Inf.

Is EXP the opposite of LN?

Mathematically yes: LN(EXP(x)) is x and EXP(LN(x)) is x for positive x. In floating point the round trip can be off in the last digits.

What is EXP(0)?

Exactly 1. e to the power zero is 1 on every engine, returned as a float 1.0.

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.