SQL EXP function
Returns e raised to the given power: EXP(1) is about 2.71828 and EXP(0) is exactly 1.
- Categoria
- Math
- Returns
float / double- In this category
- 19 of 82
Sintaxe
EXP(number)
Suporte a mecanismos
| Motor | Support | Notas |
|---|---|---|
| SQL Server | Sim | Supported under this name. |
| PostgreSQL | Sim | Supported under this name. |
| MySQL | Sim | Supported under this name. |
| SQLite | Sim | Requires SQLite 3.35+ with the math functions built in |
| Oracle | Sim | Supported under this name. |
Exemplos
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
Bom saber
- 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.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
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.